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
+10
-13
@@ -20,18 +20,16 @@ namespace Echoion::Core
|
||||
ConfigLoader::loadFromFile(const std::filesystem::path& path)
|
||||
{
|
||||
if (!std::filesystem::exists(path)) {
|
||||
return std::unexpected(
|
||||
Api::Error(Api::ErrorCode::NotFound,
|
||||
return Api::fail(Api::ErrorCode::NotFound,
|
||||
std::format("Configuration file not found: {}",
|
||||
path.string())));
|
||||
path.string()));
|
||||
}
|
||||
|
||||
std::ifstream file(path);
|
||||
if (!file.is_open()) {
|
||||
return std::unexpected(
|
||||
Api::Error(Api::ErrorCode::PermissionDenied,
|
||||
return Api::fail(Api::ErrorCode::PermissionDenied,
|
||||
std::format("Failed to open configuration file: {}",
|
||||
path.string())));
|
||||
path.string()));
|
||||
}
|
||||
|
||||
std::string content((std::istreambuf_iterator<char>(file)),
|
||||
@@ -40,11 +38,11 @@ namespace Echoion::Core
|
||||
|
||||
auto parsed = Void::Json::parse(content);
|
||||
if (!parsed) {
|
||||
return std::unexpected(Api::Error(
|
||||
return Api::fail(
|
||||
Api::ErrorCode::ParseError,
|
||||
std::format("Failed to parse configuration ({}:{}): {}",
|
||||
parsed.error().line, parsed.error().col,
|
||||
parsed.error().message)));
|
||||
parsed.error().message));
|
||||
}
|
||||
|
||||
// Tolerant deserialization: unknown JSON fields are ignored and missing
|
||||
@@ -52,11 +50,11 @@ namespace Echoion::Core
|
||||
// glz::opts{error_on_unknown_keys=false, error_on_missing_keys=false}).
|
||||
auto jsonResult = Void::Json::from_json<AppConfigJson>(*parsed);
|
||||
if (!jsonResult) {
|
||||
return std::unexpected(Api::Error(
|
||||
return Api::fail(
|
||||
Api::ErrorCode::ParseError,
|
||||
std::format("Failed to parse configuration: field '{}': {}",
|
||||
jsonResult.error().field,
|
||||
jsonResult.error().message)));
|
||||
jsonResult.error().message));
|
||||
}
|
||||
AppConfigJson jsonConfig = std::move(*jsonResult);
|
||||
|
||||
@@ -294,10 +292,9 @@ namespace Echoion::Core
|
||||
Void::Json::to_json(jsonConfig), {.pretty = true});
|
||||
std::ofstream file(path);
|
||||
if (!file.is_open()) {
|
||||
return std::unexpected(
|
||||
Api::Error(Api::ErrorCode::PermissionDenied,
|
||||
return Api::fail(Api::ErrorCode::PermissionDenied,
|
||||
std::format("Failed to write configuration file: {}",
|
||||
path.string())));
|
||||
path.string()));
|
||||
}
|
||||
|
||||
file << json;
|
||||
|
||||
Reference in new issue
Block a user