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
+87
-91
@@ -41,8 +41,8 @@ namespace Echoion::Core
|
||||
Api::Result<void> Core::initialize(const std::filesystem::path& configPath)
|
||||
{
|
||||
if (initialized_) {
|
||||
return std::unexpected(Api::Error(Api::ErrorCode::AlreadyExists,
|
||||
"Core already initialized"));
|
||||
return Api::fail(Api::ErrorCode::AlreadyExists,
|
||||
"Core already initialized");
|
||||
}
|
||||
auto logger = std::make_shared<Logger>();
|
||||
logger->setMinLevel(Api::LogLevel::Debug);
|
||||
@@ -412,8 +412,8 @@ namespace Echoion::Core
|
||||
Api::Result<void> Core::playTrack(const Api::TrackInfo& track)
|
||||
{
|
||||
if (!initialized_) {
|
||||
return std::unexpected(Api::Error(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized"));
|
||||
return Api::fail(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized");
|
||||
}
|
||||
|
||||
auto result = musicManager_->queueTrack(track, 0);
|
||||
@@ -445,8 +445,8 @@ namespace Echoion::Core
|
||||
Api::Result<void> Core::play(const std::string& trackId)
|
||||
{
|
||||
if (!initialized_) {
|
||||
return std::unexpected(Api::Error(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized"));
|
||||
return Api::fail(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized");
|
||||
}
|
||||
|
||||
// Resolve track ID to TrackInfo via MusicManager
|
||||
@@ -461,8 +461,8 @@ namespace Echoion::Core
|
||||
Api::Result<void> Core::pause()
|
||||
{
|
||||
if (!initialized_) {
|
||||
return std::unexpected(Api::Error(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized"));
|
||||
return Api::fail(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized");
|
||||
}
|
||||
|
||||
auto result = musicManager_->pause();
|
||||
@@ -478,8 +478,8 @@ namespace Echoion::Core
|
||||
Api::Result<void> Core::resume()
|
||||
{
|
||||
if (!initialized_) {
|
||||
return std::unexpected(Api::Error(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized"));
|
||||
return Api::fail(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized");
|
||||
}
|
||||
|
||||
auto result = musicManager_->resume();
|
||||
@@ -495,8 +495,8 @@ namespace Echoion::Core
|
||||
Api::Result<void> Core::stop()
|
||||
{
|
||||
if (!initialized_) {
|
||||
return std::unexpected(Api::Error(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized"));
|
||||
return Api::fail(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized");
|
||||
}
|
||||
|
||||
auto result = musicManager_->stop();
|
||||
@@ -512,8 +512,8 @@ namespace Echoion::Core
|
||||
Api::Result<void> Core::skip(uint32_t count)
|
||||
{
|
||||
if (!initialized_) {
|
||||
return std::unexpected(Api::Error(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized"));
|
||||
return Api::fail(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized");
|
||||
}
|
||||
|
||||
auto result = musicManager_->skip(count);
|
||||
@@ -529,8 +529,8 @@ namespace Echoion::Core
|
||||
Api::Result<void> Core::seek(std::chrono::milliseconds position)
|
||||
{
|
||||
if (!initialized_) {
|
||||
return std::unexpected(Api::Error(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized"));
|
||||
return Api::fail(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized");
|
||||
}
|
||||
|
||||
return musicManager_->seek(position);
|
||||
@@ -539,8 +539,8 @@ namespace Echoion::Core
|
||||
Api::Result<void> Core::setVolume(float volume)
|
||||
{
|
||||
if (!initialized_) {
|
||||
return std::unexpected(Api::Error(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized"));
|
||||
return Api::fail(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized");
|
||||
}
|
||||
|
||||
return musicManager_->setVolume(volume);
|
||||
@@ -550,8 +550,8 @@ namespace Echoion::Core
|
||||
uint64_t clientId)
|
||||
{
|
||||
if (!initialized_) {
|
||||
return std::unexpected(Api::Error(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized"));
|
||||
return Api::fail(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized");
|
||||
}
|
||||
|
||||
auto result = musicManager_->queueTrack(track, clientId);
|
||||
@@ -572,8 +572,8 @@ namespace Echoion::Core
|
||||
uint64_t clientId)
|
||||
{
|
||||
if (!initialized_) {
|
||||
return std::unexpected(Api::Error(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized"));
|
||||
return Api::fail(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized");
|
||||
}
|
||||
|
||||
// Use MusicManager::play to resolve trackId and get TrackInfo
|
||||
@@ -592,8 +592,8 @@ namespace Echoion::Core
|
||||
Api::Result<void> Core::removeFromQueue(uint64_t queueId)
|
||||
{
|
||||
if (!initialized_) {
|
||||
return std::unexpected(Api::Error(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized"));
|
||||
return Api::fail(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized");
|
||||
}
|
||||
|
||||
// Find position by queueId
|
||||
@@ -608,15 +608,14 @@ namespace Echoion::Core
|
||||
}
|
||||
}
|
||||
|
||||
return std::unexpected(
|
||||
Api::Error(Api::ErrorCode::NotFound, "Track not found in queue"));
|
||||
return Api::fail(Api::ErrorCode::NotFound, "Track not found in queue");
|
||||
}
|
||||
|
||||
Api::Result<void> Core::clearQueue()
|
||||
{
|
||||
if (!initialized_) {
|
||||
return std::unexpected(Api::Error(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized"));
|
||||
return Api::fail(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized");
|
||||
}
|
||||
|
||||
auto result = musicManager_->clearQueue();
|
||||
@@ -632,8 +631,8 @@ namespace Echoion::Core
|
||||
Api::Result<std::vector<Api::QueueEntry>> Core::getQueue() const
|
||||
{
|
||||
if (!initialized_) {
|
||||
return std::unexpected(Api::Error(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized"));
|
||||
return Api::fail(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized");
|
||||
}
|
||||
|
||||
return musicManager_->getQueue();
|
||||
@@ -642,8 +641,8 @@ namespace Echoion::Core
|
||||
Api::Result<std::vector<Api::TrackSummary>> Core::getQueueSummaries() const
|
||||
{
|
||||
if (!initialized_) {
|
||||
return std::unexpected(Api::Error(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized"));
|
||||
return Api::fail(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized");
|
||||
}
|
||||
|
||||
auto queue = musicManager_->getQueue();
|
||||
@@ -666,8 +665,8 @@ namespace Echoion::Core
|
||||
Api::Result<void> Core::moveInQueue(uint64_t queueId, uint32_t newPosition)
|
||||
{
|
||||
if (!initialized_) {
|
||||
return std::unexpected(Api::Error(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized"));
|
||||
return Api::fail(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized");
|
||||
}
|
||||
|
||||
// Find current position
|
||||
@@ -687,8 +686,8 @@ namespace Echoion::Core
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
return std::unexpected(Api::Error(Api::ErrorCode::NotFound,
|
||||
"Track not found in queue"));
|
||||
return Api::fail(Api::ErrorCode::NotFound,
|
||||
"Track not found in queue");
|
||||
}
|
||||
|
||||
return musicManager_->moveInQueue(fromPosition, newPosition);
|
||||
@@ -697,8 +696,8 @@ namespace Echoion::Core
|
||||
Api::Result<std::optional<Api::QueueEntry>> Core::getCurrentTrack() const
|
||||
{
|
||||
if (!initialized_) {
|
||||
return std::unexpected(Api::Error(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized"));
|
||||
return Api::fail(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized");
|
||||
}
|
||||
|
||||
return musicManager_->getCurrentTrack();
|
||||
@@ -708,8 +707,8 @@ namespace Echoion::Core
|
||||
Core::getCurrentTrackSummary() const
|
||||
{
|
||||
if (!initialized_) {
|
||||
return std::unexpected(Api::Error(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized"));
|
||||
return Api::fail(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized");
|
||||
}
|
||||
|
||||
auto current = musicManager_->getCurrentTrack();
|
||||
@@ -731,8 +730,8 @@ namespace Echoion::Core
|
||||
Api::Result<Api::PlaybackState> Core::getPlaybackState() const
|
||||
{
|
||||
if (!initialized_) {
|
||||
return std::unexpected(Api::Error(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized"));
|
||||
return Api::fail(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized");
|
||||
}
|
||||
|
||||
return musicManager_->getPlaybackState();
|
||||
@@ -741,8 +740,8 @@ namespace Echoion::Core
|
||||
Api::Result<Api::PlaybackSummary> Core::getPlaybackSummary() const
|
||||
{
|
||||
if (!initialized_) {
|
||||
return std::unexpected(Api::Error(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized"));
|
||||
return Api::fail(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized");
|
||||
}
|
||||
|
||||
auto state = musicManager_->getPlaybackState();
|
||||
@@ -773,8 +772,8 @@ namespace Echoion::Core
|
||||
uint64_t clientId)
|
||||
{
|
||||
if (!initialized_) {
|
||||
return std::unexpected(Api::Error(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized"));
|
||||
return Api::fail(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized");
|
||||
}
|
||||
|
||||
auto result = musicManager_->loadPlaylist(playlistId, clientId);
|
||||
@@ -787,8 +786,8 @@ namespace Echoion::Core
|
||||
Api::Result<std::vector<Api::PlaylistInfo>> Core::getPlaylists() const
|
||||
{
|
||||
if (!initialized_) {
|
||||
return std::unexpected(Api::Error(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized"));
|
||||
return Api::fail(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized");
|
||||
}
|
||||
|
||||
return musicManager_->getPlaylists();
|
||||
@@ -797,8 +796,8 @@ namespace Echoion::Core
|
||||
Api::Result<std::vector<std::string>> Core::getPlaylistIds() const
|
||||
{
|
||||
if (!initialized_) {
|
||||
return std::unexpected(Api::Error(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized"));
|
||||
return Api::fail(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized");
|
||||
}
|
||||
|
||||
auto playlists = musicManager_->getPlaylists();
|
||||
@@ -845,19 +844,19 @@ namespace Echoion::Core
|
||||
// Parse JSON config using Void::Json reflection
|
||||
auto parsed = Void::Json::parse(configJson);
|
||||
if (!parsed) {
|
||||
return std::unexpected(Api::Error(
|
||||
return Api::fail(
|
||||
Api::ErrorCode::ParseError,
|
||||
std::format("Failed to parse config JSON ({}:{}): {}",
|
||||
parsed.error().line, parsed.error().col,
|
||||
parsed.error().message)));
|
||||
parsed.error().message));
|
||||
}
|
||||
auto jsonResult = Void::Json::from_json<AppConfigJson>(*parsed);
|
||||
if (!jsonResult.has_value()) {
|
||||
return std::unexpected(Api::Error(
|
||||
return Api::fail(
|
||||
Api::ErrorCode::ParseError,
|
||||
std::format("Failed to parse config JSON: field '{}': {}",
|
||||
jsonResult.error().field,
|
||||
jsonResult.error().message)));
|
||||
jsonResult.error().message));
|
||||
}
|
||||
|
||||
// Convert to AppConfig
|
||||
@@ -976,13 +975,13 @@ namespace Echoion::Core
|
||||
Api::Result<void> Core::reloadConfig()
|
||||
{
|
||||
if (!initialized_) {
|
||||
return std::unexpected(Api::Error(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized"));
|
||||
return Api::fail(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized");
|
||||
}
|
||||
|
||||
if (configPath_.empty()) {
|
||||
return std::unexpected(Api::Error(Api::ErrorCode::InvalidArgument,
|
||||
"Config path not set"));
|
||||
return Api::fail(Api::ErrorCode::InvalidArgument,
|
||||
"Config path not set");
|
||||
}
|
||||
|
||||
// Reload config from disk
|
||||
@@ -1007,8 +1006,8 @@ namespace Echoion::Core
|
||||
Api::Result<Api::HotReloadState> Core::prepareForHotReloadFull()
|
||||
{
|
||||
if (!initialized_) {
|
||||
return std::unexpected(Api::Error(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized"));
|
||||
return Api::fail(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized");
|
||||
}
|
||||
|
||||
ECHOION_LOG_INFO("Preparing for hot reload...");
|
||||
@@ -1025,8 +1024,8 @@ namespace Echoion::Core
|
||||
Core::restoreAfterHotReloadFull(const Api::HotReloadState& state)
|
||||
{
|
||||
if (!initialized_) {
|
||||
return std::unexpected(Api::Error(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized"));
|
||||
return Api::fail(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized");
|
||||
}
|
||||
|
||||
ECHOION_LOG_INFO("Restoring after hot reload...");
|
||||
@@ -1048,8 +1047,8 @@ namespace Echoion::Core
|
||||
Api::Result<std::string> Core::prepareForHotReload()
|
||||
{
|
||||
if (!initialized_) {
|
||||
return std::unexpected(Api::Error(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized"));
|
||||
return Api::fail(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized");
|
||||
}
|
||||
|
||||
ECHOION_LOG_INFO("Preparing for hot reload (decoupled)...");
|
||||
@@ -1068,8 +1067,8 @@ namespace Echoion::Core
|
||||
Api::Result<void> Core::restoreAfterHotReload(const std::string& state)
|
||||
{
|
||||
if (!initialized_) {
|
||||
return std::unexpected(Api::Error(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized"));
|
||||
return Api::fail(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized");
|
||||
}
|
||||
|
||||
ECHOION_LOG_INFO("Restoring after hot reload (decoupled)...");
|
||||
@@ -1077,20 +1076,20 @@ namespace Echoion::Core
|
||||
// Deserialize state from JSON
|
||||
auto parsed = Void::Json::parse(state);
|
||||
if (!parsed) {
|
||||
return std::unexpected(Api::Error(
|
||||
return Api::fail(
|
||||
Api::ErrorCode::ParseError,
|
||||
std::format("Failed to parse hot reload state ({}:{}): {}",
|
||||
parsed.error().line, parsed.error().col,
|
||||
parsed.error().message)));
|
||||
parsed.error().message));
|
||||
}
|
||||
auto stateResult = Void::Json::from_json<Api::HotReloadState>(*parsed);
|
||||
if (!stateResult.has_value()) {
|
||||
return std::unexpected(Api::Error(
|
||||
return Api::fail(
|
||||
Api::ErrorCode::ParseError,
|
||||
std::format("Failed to deserialize hot reload state: "
|
||||
"field '{}': {}",
|
||||
stateResult.error().field,
|
||||
stateResult.error().message)));
|
||||
stateResult.error().message));
|
||||
}
|
||||
|
||||
auto result = musicManager_->restoreFromHotReload(stateResult.value());
|
||||
@@ -1223,8 +1222,8 @@ namespace Echoion::Core
|
||||
Core::getCurrentTrackHandle() const
|
||||
{
|
||||
if (!initialized_) {
|
||||
return std::unexpected(Api::Error(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized"));
|
||||
return Api::fail(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized");
|
||||
}
|
||||
|
||||
auto current = musicManager_->getCurrentTrack();
|
||||
@@ -1246,8 +1245,8 @@ namespace Echoion::Core
|
||||
Core::getQueueHandles() const
|
||||
{
|
||||
if (!initialized_) {
|
||||
return std::unexpected(Api::Error(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized"));
|
||||
return Api::fail(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized");
|
||||
}
|
||||
|
||||
auto queue = musicManager_->getQueue();
|
||||
@@ -1274,8 +1273,8 @@ namespace Echoion::Core
|
||||
Api::Result<void> Core::updateConfigFromHandle(Api::AppConfigHandle config)
|
||||
{
|
||||
if (!config.isValid()) {
|
||||
return std::unexpected(Api::Error(Api::ErrorCode::InvalidArgument,
|
||||
"Invalid config handle"));
|
||||
return Api::fail(Api::ErrorCode::InvalidArgument,
|
||||
"Invalid config handle");
|
||||
}
|
||||
|
||||
// Update from the handle
|
||||
@@ -1307,8 +1306,8 @@ namespace Echoion::Core
|
||||
"(this={}), ignoring event type={}",
|
||||
reinterpret_cast<uintptr_t>(this),
|
||||
static_cast<int>(event.type)));
|
||||
return std::unexpected(Api::Error(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized"));
|
||||
return Api::fail(
|
||||
Api::ErrorCode::ServiceUnavailable, "Core not initialized");
|
||||
}
|
||||
|
||||
// Debug logging for command events
|
||||
@@ -1628,16 +1627,14 @@ namespace Echoion::Core
|
||||
// Parse JSON params
|
||||
auto parsedParams = Void::Json::parse(params);
|
||||
if (!parsedParams) {
|
||||
return std::unexpected(
|
||||
Api::Error(Api::ErrorCode::InvalidArgument,
|
||||
"Invalid authentication request format"));
|
||||
return Api::fail(Api::ErrorCode::InvalidArgument,
|
||||
"Invalid authentication request format");
|
||||
}
|
||||
auto reqResult =
|
||||
Void::Json::from_json<RpcAuthRequest>(*parsedParams);
|
||||
if (!reqResult) {
|
||||
return std::unexpected(
|
||||
Api::Error(Api::ErrorCode::InvalidArgument,
|
||||
"Invalid authentication request format"));
|
||||
return Api::fail(Api::ErrorCode::InvalidArgument,
|
||||
"Invalid authentication request format");
|
||||
}
|
||||
const RpcAuthRequest& req = *reqResult;
|
||||
|
||||
@@ -1653,8 +1650,8 @@ namespace Echoion::Core
|
||||
"{\"success\":true,\"message\":\"Authentication "
|
||||
"successful\"}");
|
||||
} else {
|
||||
return std::unexpected(Api::Error(
|
||||
Api::ErrorCode::PermissionDenied, "Invalid token"));
|
||||
return Api::fail(
|
||||
Api::ErrorCode::PermissionDenied, "Invalid token");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1668,10 +1665,10 @@ namespace Echoion::Core
|
||||
}
|
||||
|
||||
if (!uidResult->has_value()) {
|
||||
return std::unexpected(Api::Error(
|
||||
return Api::fail(
|
||||
Api::ErrorCode::NotFound,
|
||||
"Subscriber not found. Please subscribe to the bot "
|
||||
"first using !subscribe command."));
|
||||
"first using !subscribe command.");
|
||||
}
|
||||
|
||||
const std::string& uid = **uidResult;
|
||||
@@ -1736,10 +1733,9 @@ namespace Echoion::Core
|
||||
"TeamSpeak PM. Please check your private messages.\"}");
|
||||
}
|
||||
|
||||
return std::unexpected(
|
||||
Api::Error(Api::ErrorCode::InvalidArgument,
|
||||
return Api::fail(Api::ErrorCode::InvalidArgument,
|
||||
"Authentication request must include either "
|
||||
"'nickname' or 'token'"));
|
||||
"'nickname' or 'token'");
|
||||
});
|
||||
|
||||
// Playback control
|
||||
|
||||
Reference in new issue
Block a user