Use Api::fail() for error returns (241 sites)
Mechanically convert std::unexpected(Api::Error(ErrorCode::X, msg[, src])) to Api::fail(ErrorCode::X, msg[, src]) across Core. Pure syntax; forwards of existing errors (std::unexpected(x.error())) are unchanged. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
f8757d6040
commit
23759899bb
14 files changed
+344
-435
No files matched your search
+62
-77
@@ -181,9 +181,8 @@ namespace Echoion::Core
|
||||
Api::Result<void> YouTubeClient::updateYtDlp()
|
||||
{
|
||||
if (!ytDlpManager_) {
|
||||
return std::unexpected(
|
||||
Api::Error(Api::ErrorCode::ServiceUnavailable,
|
||||
"yt-dlp manager not initialized"));
|
||||
return Api::fail(Api::ErrorCode::ServiceUnavailable,
|
||||
"yt-dlp manager not initialized");
|
||||
}
|
||||
return ytDlpManager_->update();
|
||||
}
|
||||
@@ -192,19 +191,18 @@ namespace Echoion::Core
|
||||
YouTubeClient::getAudioStreamUrl(std::string_view videoId)
|
||||
{
|
||||
if (!initialized_) {
|
||||
return std::unexpected(
|
||||
Api::Error(Api::ErrorCode::ServiceUnavailable,
|
||||
"YouTubeClient not initialized"));
|
||||
return Api::fail(Api::ErrorCode::ServiceUnavailable,
|
||||
"YouTubeClient not initialized");
|
||||
}
|
||||
|
||||
if (!ytDlpManager_->isAvailable()) {
|
||||
return std::unexpected(Api::Error(
|
||||
Api::ErrorCode::ServiceUnavailable, "yt-dlp not available"));
|
||||
return Api::fail(
|
||||
Api::ErrorCode::ServiceUnavailable, "yt-dlp not available");
|
||||
}
|
||||
|
||||
if (videoId.empty()) {
|
||||
return std::unexpected(Api::Error(Api::ErrorCode::InvalidArgument,
|
||||
"Video ID is empty"));
|
||||
return Api::fail(Api::ErrorCode::InvalidArgument,
|
||||
"Video ID is empty");
|
||||
}
|
||||
|
||||
auto startTime = std::chrono::steady_clock::now();
|
||||
@@ -227,18 +225,16 @@ namespace Echoion::Core
|
||||
if (waitStatus == std::future_status::timeout) {
|
||||
ECHOION_LOG_WARNING(
|
||||
"yt-dlp audio URL extraction timed out after 30s");
|
||||
return std::unexpected(
|
||||
Api::Error(Api::ErrorCode::NetworkError,
|
||||
"yt-dlp audio URL extraction timed out"));
|
||||
return Api::fail(Api::ErrorCode::NetworkError,
|
||||
"yt-dlp audio URL extraction timed out");
|
||||
}
|
||||
|
||||
auto ytdlpResult = future.get();
|
||||
|
||||
if (!ytdlpResult.success) {
|
||||
ECHOION_LOG_WARNING("yt-dlp audio URL extraction failed");
|
||||
return std::unexpected(
|
||||
Api::Error(Api::ErrorCode::NetworkError,
|
||||
"yt-dlp audio URL extraction failed"));
|
||||
return Api::fail(Api::ErrorCode::NetworkError,
|
||||
"yt-dlp audio URL extraction failed");
|
||||
}
|
||||
|
||||
std::string result = ytdlpResult.output;
|
||||
@@ -259,8 +255,8 @@ namespace Echoion::Core
|
||||
|
||||
ECHOION_LOG_WARNING(std::format(
|
||||
"Failed to get audio URL from yt-dlp after {} ms", elapsed));
|
||||
return std::unexpected(Api::Error(
|
||||
Api::ErrorCode::NotFound, "Failed to get audio URL from yt-dlp"));
|
||||
return Api::fail(
|
||||
Api::ErrorCode::NotFound, "Failed to get audio URL from yt-dlp");
|
||||
}
|
||||
|
||||
Api::Result<std::string>
|
||||
@@ -273,20 +269,19 @@ namespace Echoion::Core
|
||||
YouTubeClient::getVideoInfo(std::string_view videoId)
|
||||
{
|
||||
if (!initialized_) {
|
||||
return std::unexpected(
|
||||
Api::Error(Api::ErrorCode::ServiceUnavailable,
|
||||
"YouTubeClient not initialized"));
|
||||
return Api::fail(Api::ErrorCode::ServiceUnavailable,
|
||||
"YouTubeClient not initialized");
|
||||
}
|
||||
|
||||
if (!ytDlpManager_->isAvailable()) {
|
||||
return std::unexpected(Api::Error(
|
||||
Api::ErrorCode::ServiceUnavailable, "yt-dlp not available"));
|
||||
return Api::fail(
|
||||
Api::ErrorCode::ServiceUnavailable, "yt-dlp not available");
|
||||
}
|
||||
|
||||
// Validate video ID
|
||||
if (videoId.empty()) {
|
||||
return std::unexpected(Api::Error(Api::ErrorCode::InvalidArgument,
|
||||
"Video ID is empty"));
|
||||
return Api::fail(Api::ErrorCode::InvalidArgument,
|
||||
"Video ID is empty");
|
||||
}
|
||||
|
||||
ECHOION_LOG_DEBUG(
|
||||
@@ -304,8 +299,8 @@ namespace Echoion::Core
|
||||
|
||||
if (waitStatus == std::future_status::timeout) {
|
||||
ECHOION_LOG_WARNING("yt-dlp video info timed out after 30s");
|
||||
return std::unexpected(Api::Error(Api::ErrorCode::NetworkError,
|
||||
"yt-dlp video info timed out"));
|
||||
return Api::fail(Api::ErrorCode::NetworkError,
|
||||
"yt-dlp video info timed out");
|
||||
}
|
||||
|
||||
auto ytdlpResult = result.get();
|
||||
@@ -317,17 +312,15 @@ namespace Echoion::Core
|
||||
.count()));
|
||||
|
||||
if (!ytdlpResult.success || ytdlpResult.output.empty()) {
|
||||
return std::unexpected(
|
||||
Api::Error(Api::ErrorCode::NetworkError,
|
||||
"yt-dlp failed to get video info"));
|
||||
return Api::fail(Api::ErrorCode::NetworkError,
|
||||
"yt-dlp failed to get video info");
|
||||
}
|
||||
|
||||
try {
|
||||
auto parsed = Void::Json::parse(ytdlpResult.output);
|
||||
if (!parsed) {
|
||||
return std::unexpected(
|
||||
Api::Error(Api::ErrorCode::ParseError,
|
||||
"Failed to parse yt-dlp output"));
|
||||
return Api::fail(Api::ErrorCode::ParseError,
|
||||
"Failed to parse yt-dlp output");
|
||||
}
|
||||
const JValue& json = *parsed;
|
||||
|
||||
@@ -354,9 +347,9 @@ namespace Echoion::Core
|
||||
return info;
|
||||
|
||||
} catch (const std::exception& e) {
|
||||
return std::unexpected(Api::Error(
|
||||
return Api::fail(
|
||||
Api::ErrorCode::ParseError,
|
||||
std::format("Exception parsing yt-dlp output: {}", e.what())));
|
||||
std::format("Exception parsing yt-dlp output: {}", e.what()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -397,9 +390,8 @@ namespace Echoion::Core
|
||||
{
|
||||
|
||||
if (!initialized_) {
|
||||
return std::unexpected(
|
||||
Api::Error(Api::ErrorCode::ServiceUnavailable,
|
||||
"YouTubeClient not initialized"));
|
||||
return Api::fail(Api::ErrorCode::ServiceUnavailable,
|
||||
"YouTubeClient not initialized");
|
||||
}
|
||||
|
||||
auto startTime = std::chrono::steady_clock::now();
|
||||
@@ -433,9 +425,8 @@ namespace Echoion::Core
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(configMutex_);
|
||||
if (!apiKey_.has_value() || apiKey_->empty()) {
|
||||
return std::unexpected(
|
||||
Api::Error(Api::ErrorCode::ServiceUnavailable,
|
||||
"YouTube API key not configured"));
|
||||
return Api::fail(Api::ErrorCode::ServiceUnavailable,
|
||||
"YouTube API key not configured");
|
||||
}
|
||||
apiKey = *apiKey_;
|
||||
}
|
||||
@@ -477,8 +468,8 @@ namespace Echoion::Core
|
||||
if (waitStatus == std::future_status::timeout) {
|
||||
ECHOION_LOG_WARNING("YouTube API search timed out after 10s");
|
||||
apiThread.detach(); // Thread owns shared_ptr, safe to detach
|
||||
return std::unexpected(Api::Error(Api::ErrorCode::NetworkError,
|
||||
"YouTube API search timed out"));
|
||||
return Api::fail(Api::ErrorCode::NetworkError,
|
||||
"YouTube API search timed out");
|
||||
}
|
||||
|
||||
ECHOION_LOG_DEBUG("Joining API request thread...");
|
||||
@@ -492,9 +483,8 @@ namespace Echoion::Core
|
||||
} catch (const std::exception& e) {
|
||||
ECHOION_LOG_ERROR(
|
||||
std::format("API request threw exception: {}", e.what()));
|
||||
return std::unexpected(
|
||||
Api::Error(Api::ErrorCode::NetworkError,
|
||||
std::format("API request failed: {}", e.what())));
|
||||
return Api::fail(Api::ErrorCode::NetworkError,
|
||||
std::format("API request failed: {}", e.what()));
|
||||
}
|
||||
|
||||
// Log response status
|
||||
@@ -507,19 +497,18 @@ namespace Echoion::Core
|
||||
}
|
||||
|
||||
if (!response || !response->isSuccess()) {
|
||||
return std::unexpected(Api::Error(
|
||||
return Api::fail(
|
||||
Api::ErrorCode::NetworkError,
|
||||
std::format("YouTube API search failed: {}",
|
||||
response ? std::to_string(response->statusCode)
|
||||
: "no response")));
|
||||
: "no response"));
|
||||
}
|
||||
|
||||
try {
|
||||
auto parsed = Void::Json::parse(response->body);
|
||||
if (!parsed) {
|
||||
return std::unexpected(
|
||||
Api::Error(Api::ErrorCode::ParseError,
|
||||
"Failed to parse YouTube API search response"));
|
||||
return Api::fail(Api::ErrorCode::ParseError,
|
||||
"Failed to parse YouTube API search response");
|
||||
}
|
||||
const JValue& json = *parsed;
|
||||
|
||||
@@ -608,10 +597,10 @@ namespace Echoion::Core
|
||||
return result;
|
||||
|
||||
} catch (const std::exception& e) {
|
||||
return std::unexpected(Api::Error(
|
||||
return Api::fail(
|
||||
Api::ErrorCode::ParseError,
|
||||
std::format("Exception parsing YouTube API search: {}",
|
||||
e.what())));
|
||||
e.what()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -738,8 +727,8 @@ namespace Echoion::Core
|
||||
{
|
||||
|
||||
if (!ytDlpManager_->isAvailable()) {
|
||||
return std::unexpected(Api::Error(
|
||||
Api::ErrorCode::ServiceUnavailable, "yt-dlp not available"));
|
||||
return Api::fail(
|
||||
Api::ErrorCode::ServiceUnavailable, "yt-dlp not available");
|
||||
}
|
||||
|
||||
ECHOION_LOG_DEBUG("Starting yt-dlp search...");
|
||||
@@ -757,8 +746,8 @@ namespace Echoion::Core
|
||||
|
||||
if (waitStatus == std::future_status::timeout) {
|
||||
ECHOION_LOG_WARNING("yt-dlp search timed out after 30s");
|
||||
return std::unexpected(Api::Error(Api::ErrorCode::NetworkError,
|
||||
"yt-dlp search timed out"));
|
||||
return Api::fail(Api::ErrorCode::NetworkError,
|
||||
"yt-dlp search timed out");
|
||||
}
|
||||
|
||||
auto ytdlpResult = result.get();
|
||||
@@ -770,16 +759,15 @@ namespace Echoion::Core
|
||||
std::format("yt-dlp search completed in {} ms", elapsed));
|
||||
|
||||
if (!ytdlpResult.success || ytdlpResult.output.empty()) {
|
||||
return std::unexpected(Api::Error(Api::ErrorCode::NetworkError,
|
||||
"yt-dlp search failed"));
|
||||
return Api::fail(Api::ErrorCode::NetworkError,
|
||||
"yt-dlp search failed");
|
||||
}
|
||||
|
||||
try {
|
||||
auto parsed = Void::Json::parse(ytdlpResult.output);
|
||||
if (!parsed) {
|
||||
return std::unexpected(
|
||||
Api::Error(Api::ErrorCode::ParseError,
|
||||
"Failed to parse yt-dlp search output"));
|
||||
return Api::fail(Api::ErrorCode::ParseError,
|
||||
"Failed to parse yt-dlp search output");
|
||||
}
|
||||
const JValue& json = *parsed;
|
||||
|
||||
@@ -829,9 +817,9 @@ namespace Echoion::Core
|
||||
return searchResult;
|
||||
|
||||
} catch (const std::exception& e) {
|
||||
return std::unexpected(Api::Error(
|
||||
return Api::fail(
|
||||
Api::ErrorCode::ParseError,
|
||||
std::format("Exception parsing yt-dlp search: {}", e.what())));
|
||||
std::format("Exception parsing yt-dlp search: {}", e.what()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -839,9 +827,8 @@ namespace Echoion::Core
|
||||
YouTubeClient::getPlaylist(std::string_view playlistId)
|
||||
{
|
||||
if (!initialized_) {
|
||||
return std::unexpected(
|
||||
Api::Error(Api::ErrorCode::ServiceUnavailable,
|
||||
"YouTubeClient not initialized"));
|
||||
return Api::fail(Api::ErrorCode::ServiceUnavailable,
|
||||
"YouTubeClient not initialized");
|
||||
}
|
||||
|
||||
ECHOION_LOG_INFO(std::format("Fetching playlist: {}", playlistId));
|
||||
@@ -1113,8 +1100,8 @@ namespace Echoion::Core
|
||||
ECHOION_LOG_INFO("Using yt-dlp for playlist fetch");
|
||||
|
||||
if (!ytDlpManager_->isAvailable()) {
|
||||
return std::unexpected(Api::Error(
|
||||
Api::ErrorCode::ServiceUnavailable, "yt-dlp not available"));
|
||||
return Api::fail(
|
||||
Api::ErrorCode::ServiceUnavailable, "yt-dlp not available");
|
||||
}
|
||||
|
||||
std::string url =
|
||||
@@ -1126,17 +1113,15 @@ namespace Echoion::Core
|
||||
auto ytdlpResult = result.get();
|
||||
|
||||
if (!ytdlpResult.success || ytdlpResult.output.empty()) {
|
||||
return std::unexpected(
|
||||
Api::Error(Api::ErrorCode::NetworkError,
|
||||
"Failed to fetch playlist via yt-dlp"));
|
||||
return Api::fail(Api::ErrorCode::NetworkError,
|
||||
"Failed to fetch playlist via yt-dlp");
|
||||
}
|
||||
|
||||
try {
|
||||
auto parsed = Void::Json::parse(ytdlpResult.output);
|
||||
if (!parsed) {
|
||||
return std::unexpected(
|
||||
Api::Error(Api::ErrorCode::ParseError,
|
||||
"Failed to parse yt-dlp playlist output"));
|
||||
return Api::fail(Api::ErrorCode::ParseError,
|
||||
"Failed to parse yt-dlp playlist output");
|
||||
}
|
||||
const JValue& json = *parsed;
|
||||
|
||||
@@ -1168,9 +1153,9 @@ namespace Echoion::Core
|
||||
return items;
|
||||
|
||||
} catch (const std::exception& e) {
|
||||
return std::unexpected(Api::Error(
|
||||
return Api::fail(
|
||||
Api::ErrorCode::ParseError,
|
||||
std::format("Exception parsing playlist: {}", e.what())));
|
||||
std::format("Exception parsing playlist: {}", e.what()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user