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:
faumarayandClaude Opus 4.8 committed 2026-06-22 22:07:18 +03:00
1 parent f8757d6040
commit 23759899bb
14 files changed
+344 -435

No files matched your search

+57 -73
View File
@@ -317,8 +317,8 @@ namespace Echoion::Core
std::shared_lock<std::shared_mutex> lock(mutex_);
if (!isPlaying_ || isPaused_) {
return std::unexpected(Api::Error(Api::ErrorCode::InvalidArgument,
"Nothing is playing"));
return Api::fail(Api::ErrorCode::InvalidArgument,
"Nothing is playing");
}
// Capture current position before pausing
@@ -334,8 +334,7 @@ namespace Echoion::Core
std::shared_lock<std::shared_mutex> lock(mutex_);
if (!isPlaying_ || !isPaused_) {
return std::unexpected(
Api::Error(Api::ErrorCode::InvalidArgument, "Not paused"));
return Api::fail(Api::ErrorCode::InvalidArgument, "Not paused");
}
// Reset time tracking from current position
@@ -410,8 +409,8 @@ namespace Echoion::Core
std::shared_lock<std::shared_mutex> lock(mutex_);
if (!isPlaying_) {
return std::unexpected(Api::Error(Api::ErrorCode::InvalidArgument,
"Nothing is playing"));
return Api::fail(Api::ErrorCode::InvalidArgument,
"Nothing is playing");
}
for (uint32_t i = 0; i < count; ++i) {
@@ -458,8 +457,8 @@ namespace Echoion::Core
Api::Result<void> MusicManager::seek(std::chrono::milliseconds position)
{
if (!isPlaying_) {
return std::unexpected(Api::Error(Api::ErrorCode::InvalidArgument,
"Nothing is playing"));
return Api::fail(Api::ErrorCode::InvalidArgument,
"Nothing is playing");
}
auto result = audioDecoder_->seek(position);
@@ -485,8 +484,8 @@ namespace Echoion::Core
Api::Result<void> MusicManager::setVolume(float volume)
{
if (volume < 0.0f || volume > 1.0f) {
return std::unexpected(Api::Error(Api::ErrorCode::InvalidArgument,
"Volume must be 0.0-1.0"));
return Api::fail(Api::ErrorCode::InvalidArgument,
"Volume must be 0.0-1.0");
}
float oldVolume = volume_;
@@ -516,10 +515,9 @@ namespace Echoion::Core
ECHOION_LOG_WARNING(std::format(
"Track validation failed for '{} - {}': {}", track.title,
track.artist, streamUrl.error().message));
return std::unexpected(
Api::Error(Api::ErrorCode::ServiceUnavailable,
return Api::fail(Api::ErrorCode::ServiceUnavailable,
std::format("Cannot play this track: {}",
streamUrl.error().message)));
streamUrl.error().message));
}
uint64_t queueId;
@@ -538,8 +536,8 @@ namespace Echoion::Core
std::shared_lock<std::shared_mutex> lock(mutex_);
if (queue_.size() >= config_.maxQueueSize) {
return std::unexpected(Api::Error(
Api::ErrorCode::InvalidArgument, "Queue is full"));
return Api::fail(
Api::ErrorCode::InvalidArgument, "Queue is full");
}
queueId = nextQueueId_++;
@@ -632,8 +630,8 @@ namespace Echoion::Core
std::shared_lock<std::shared_mutex> lock(mutex_);
if (position >= queue_.size()) {
return std::unexpected(Api::Error(Api::ErrorCode::InvalidArgument,
"Invalid position"));
return Api::fail(Api::ErrorCode::InvalidArgument,
"Invalid position");
}
auto removedTrack = queue_[position];
@@ -706,8 +704,8 @@ namespace Echoion::Core
std::shared_lock<std::shared_mutex> lock(mutex_);
if (from >= queue_.size() || to >= queue_.size()) {
return std::unexpected(Api::Error(Api::ErrorCode::InvalidArgument,
"Invalid position"));
return Api::fail(Api::ErrorCode::InvalidArgument,
"Invalid position");
}
auto entry = queue_[from];
@@ -828,16 +826,14 @@ namespace Echoion::Core
uint64_t clientId)
{
if (!youTubeClient_) {
return std::unexpected(
Api::Error(Api::ErrorCode::ServiceUnavailable,
"YouTube client not available"));
return Api::fail(Api::ErrorCode::ServiceUnavailable,
"YouTube client not available");
}
// Check if already loading a playlist
if (playlistLoading_.load()) {
return std::unexpected(
Api::Error(Api::ErrorCode::AlreadyExists,
"Already loading a playlist, please wait"));
return Api::fail(Api::ErrorCode::AlreadyExists,
"Already loading a playlist, please wait");
}
// Extract playlist ID if a full URL was provided
@@ -850,9 +846,8 @@ namespace Echoion::Core
ECHOION_LOG_DEBUG(std::format(
"Extracted playlist ID '{}' from URL", playlistId));
} else {
return std::unexpected(
Api::Error(Api::ErrorCode::InvalidArgument,
"Could not extract playlist ID from URL"));
return Api::fail(Api::ErrorCode::InvalidArgument,
"Could not extract playlist ID from URL");
}
}
@@ -1042,9 +1037,8 @@ namespace Echoion::Core
MusicManager::search(const std::string& query)
{
if (!youTubeClient_) {
return std::unexpected(
Api::Error(Api::ErrorCode::ServiceUnavailable,
"YouTube client not available"));
return Api::fail(Api::ErrorCode::ServiceUnavailable,
"YouTube client not available");
}
return youTubeClient_->search(query);
@@ -1078,23 +1072,22 @@ namespace Echoion::Core
{
if (index == 0) {
return std::unexpected(Api::Error(Api::ErrorCode::InvalidArgument,
"Index must be 1 or greater"));
return Api::fail(Api::ErrorCode::InvalidArgument,
"Index must be 1 or greater");
}
auto pending = getPendingSearch(clientId);
if (!pending) {
return std::unexpected(
Api::Error(Api::ErrorCode::NotFound,
return Api::fail(Api::ErrorCode::NotFound,
"No pending search results. Use search or play "
"commands first."));
"commands first.");
}
if (index > pending->size()) {
return std::unexpected(Api::Error(
return Api::fail(
Api::ErrorCode::NotFound,
std::format("Invalid selection. Only {} results available.",
pending->size())));
pending->size()));
}
auto selected =
@@ -1689,8 +1682,7 @@ namespace Echoion::Core
}
if (searchResult->tracks.empty()) {
return std::unexpected(
Api::Error(Api::ErrorCode::NotFound, "No results found"));
return Api::fail(Api::ErrorCode::NotFound, "No results found");
}
return searchResult->tracks[0];
@@ -1722,8 +1714,7 @@ namespace Echoion::Core
ECHOION_LOG_WARNING("Could not extract video ID from URL");
}
return std::unexpected(
Api::Error(Api::ErrorCode::NotFound, "Could not get stream URL"));
return Api::fail(Api::ErrorCode::NotFound, "Could not get stream URL");
}
void MusicManager::onTrackFinished()
@@ -1896,21 +1887,20 @@ Subscriptions are persistent across server reconnects.)";
Api::Result<std::string> MusicManager::subscribe(uint64_t clientId)
{
if (!subscriptionManager_) {
return std::unexpected(
Api::Error(Api::ErrorCode::ServiceUnavailable,
"Subscription manager not initialized"));
return Api::fail(Api::ErrorCode::ServiceUnavailable,
"Subscription manager not initialized");
}
// Get client info (UID and nickname) from the callback
if (!clientInfoCallback_) {
return std::unexpected(Api::Error(Api::ErrorCode::NotInitialized,
"Client info callback not set"));
return Api::fail(Api::ErrorCode::NotInitialized,
"Client info callback not set");
}
auto clientInfo = clientInfoCallback_(clientId);
if (!clientInfo) {
return std::unexpected(Api::Error(Api::ErrorCode::NotFound,
"Could not get client info"));
return Api::fail(Api::ErrorCode::NotFound,
"Could not get client info");
}
const auto& [uid, nickname] = *clientInfo;
@@ -1951,21 +1941,20 @@ Subscriptions are persistent across server reconnects.)";
Api::Result<std::string> MusicManager::unsubscribe(uint64_t clientId)
{
if (!subscriptionManager_) {
return std::unexpected(
Api::Error(Api::ErrorCode::ServiceUnavailable,
"Subscription manager not initialized"));
return Api::fail(Api::ErrorCode::ServiceUnavailable,
"Subscription manager not initialized");
}
// Get client UID from the callback
if (!clientInfoCallback_) {
return std::unexpected(Api::Error(Api::ErrorCode::NotInitialized,
"Client info callback not set"));
return Api::fail(Api::ErrorCode::NotInitialized,
"Client info callback not set");
}
auto clientInfo = clientInfoCallback_(clientId);
if (!clientInfo) {
return std::unexpected(Api::Error(Api::ErrorCode::NotFound,
"Could not get client info"));
return Api::fail(Api::ErrorCode::NotFound,
"Could not get client info");
}
const auto& [uid, nickname] = *clientInfo;
@@ -2000,9 +1989,8 @@ Subscriptions are persistent across server reconnects.)";
MusicManager::unsubscribeByUid(const std::string& uid)
{
if (!subscriptionManager_) {
return std::unexpected(
Api::Error(Api::ErrorCode::ServiceUnavailable,
"Subscription manager not initialized"));
return Api::fail(Api::ErrorCode::ServiceUnavailable,
"Subscription manager not initialized");
}
bool removed = subscriptionManager_->unsubscribe(uid);
@@ -2031,9 +2019,8 @@ Subscriptions are persistent across server reconnects.)";
Api::Result<std::string> MusicManager::clearAllSubscriptions()
{
if (!subscriptionManager_) {
return std::unexpected(
Api::Error(Api::ErrorCode::ServiceUnavailable,
"Subscription manager not initialized"));
return Api::fail(Api::ErrorCode::ServiceUnavailable,
"Subscription manager not initialized");
}
bool cleared = subscriptionManager_->clearAll();
@@ -2251,9 +2238,8 @@ Subscriptions are persistent across server reconnects.)";
MusicManager::downloadAudioForPlayback(const std::string& url)
{
if (!networkClient_) {
return std::unexpected(
Api::Error(Api::ErrorCode::ServiceUnavailable,
"NetworkClient not available"));
return Api::fail(Api::ErrorCode::ServiceUnavailable,
"NetworkClient not available");
}
// Create temp file path
@@ -2272,25 +2258,23 @@ Subscriptions are persistent across server reconnects.)";
auto response = networkClient_->get(url);
if (!response) {
return std::unexpected(
Api::Error(Api::ErrorCode::NetworkError,
return Api::fail(Api::ErrorCode::NetworkError,
std::format("Failed to download audio: {}",
response.error().message)));
response.error().message));
}
if (response->statusCode != 200) {
return std::unexpected(Api::Error(
return Api::fail(
Api::ErrorCode::NetworkError,
std::format("HTTP error {}: {}", response->statusCode,
response->body.substr(0, 100))));
response->body.substr(0, 100)));
}
// Write to temp file
std::ofstream file(tempPath, std::ios::binary);
if (!file) {
return std::unexpected(
Api::Error(Api::ErrorCode::ServiceUnavailable,
"Failed to create temp file"));
return Api::fail(Api::ErrorCode::ServiceUnavailable,
"Failed to create temp file");
}
file.write(response->body.data(), response->body.size());