Skip to content

Commit

Permalink
rpcdaemon: enum values for protocol error codes (#2146)
Browse files Browse the repository at this point in the history
  • Loading branch information
canepat authored Jun 27, 2024
1 parent a72fa98 commit 6e83c0e
Show file tree
Hide file tree
Showing 16 changed files with 527 additions and 486 deletions.
11 changes: 5 additions & 6 deletions silkworm/rpc/commands/admin_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <silkworm/infra/common/log.hpp>
#include <silkworm/rpc/json/types.hpp>
#include <silkworm/rpc/protocol/errors.hpp>

namespace silkworm::rpc::commands {

Expand All @@ -34,12 +35,11 @@ Task<void> AdminRpcApi::handle_admin_node_info(const nlohmann::json& request, nl
}
} catch (const std::exception& e) {
SILK_ERROR << "exception: " << e.what() << " processing request: " << request.dump();
reply = make_json_error(request, -32000, e.what());
reply = make_json_error(request, kServerError, e.what());
} catch (...) {
SILK_ERROR << "unexpected exception processing request: " << request.dump();
reply = make_json_error(request, 100, "unexpected exception");
reply = make_json_error(request, kServerError, "unexpected exception");
}
co_return;
}

// https://eth.wiki/json-rpc/API#admin_peers
Expand All @@ -49,12 +49,11 @@ Task<void> AdminRpcApi::handle_admin_peers(const nlohmann::json& request, nlohma
reply = make_json_content(request, peers);
} catch (const std::exception& e) {
SILK_ERROR << "exception: " << e.what() << " processing request: " << request.dump();
reply = make_json_error(request, -32000, e.what());
reply = make_json_error(request, kServerError, e.what());
} catch (...) {
SILK_ERROR << "unexpected exception processing request: " << request.dump();
reply = make_json_error(request, 100, "unexpected exception");
reply = make_json_error(request, kServerError, "unexpected exception");
}
co_return;
}

} // namespace silkworm::rpc::commands
115 changes: 51 additions & 64 deletions silkworm/rpc/commands/debug_api.cpp

Large diffs are not rendered by default.

27 changes: 9 additions & 18 deletions silkworm/rpc/commands/engine_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,13 @@ Task<void> EngineRpcApi::handle_engine_get_payload_v1(const nlohmann::json& requ
#ifndef BUILD_COVERAGE
} catch (const boost::system::system_error& se) {
SILK_ERROR << "error: \"" << se.code().message() << "\" processing request: " << request.dump();
// TODO(canepat) the error code should be se.code().value() here: application-level errors should come from BackEnd
reply = make_json_error(request, kUnknownPayload, se.code().message());
reply = make_json_error(request, se.code().value(), se.code().message());
} catch (const std::exception& e) {
SILK_ERROR << "exception: " << e.what() << " processing request: " << request.dump();
// TODO(canepat) the error code should be kInternalError here: application-level errors should come from BackEnd
reply = make_json_error(request, kUnknownPayload, e.what());
reply = make_json_error(request, kInternalError, e.what());
} catch (...) {
SILK_ERROR << "unexpected exception processing request: " << request.dump();
// TODO(canepat) the error code should be kServerError here: application-level errors should come from BackEnd
reply = make_json_error(request, kUnknownPayload, "unexpected exception");
reply = make_json_error(request, kServerError, "unexpected exception");
}
#endif
}
Expand All @@ -139,16 +136,13 @@ Task<void> EngineRpcApi::handle_engine_get_payload_v2(const nlohmann::json& requ
reply = make_json_content(request, payload_and_value);
} catch (const boost::system::system_error& se) {
SILK_ERROR << "error: \"" << se.code().message() << "\" processing request: " << request.dump();
// TODO(canepat) the error code should be se.code().value() here: application-level errors should come from BackEnd
reply = make_json_error(request, kUnknownPayload, se.code().message());
reply = make_json_error(request, se.code().value(), se.code().message());
} catch (const std::exception& e) {
SILK_ERROR << "exception: " << e.what() << " processing request: " << request.dump();
// TODO(canepat) the error code should be kInternalError here: application-level errors should come from BackEnd
reply = make_json_error(request, kUnknownPayload, e.what());
reply = make_json_error(request, kInternalError, e.what());
} catch (...) {
SILK_ERROR << "unexpected exception processing request: " << request.dump();
// TODO(canepat) the error code should be kServerError here: application-level errors should come from BackEnd
reply = make_json_error(request, kUnknownPayload, "unexpected exception");
reply = make_json_error(request, kServerError, "unexpected exception");
}
}

Expand All @@ -175,16 +169,13 @@ Task<void> EngineRpcApi::handle_engine_get_payload_v3(const nlohmann::json& requ
reply = make_json_content(request, payload_and_value);
} catch (const boost::system::system_error& se) {
SILK_ERROR << "error: \"" << se.code().message() << "\" processing request: " << request.dump();
// TODO(canepat) the error code should be se.code().value() here: application-level errors should come from BackEnd
reply = make_json_error(request, kUnknownPayload, se.code().message());
reply = make_json_error(request, se.code().value(), se.code().message());
} catch (const std::exception& e) {
SILK_ERROR << "exception: " << e.what() << " processing request: " << request.dump();
// TODO(canepat) the error code should be kInternalError here: application-level errors should come from BackEnd
reply = make_json_error(request, kUnknownPayload, e.what());
reply = make_json_error(request, kInternalError, e.what());
} catch (...) {
SILK_ERROR << "unexpected exception processing request: " << request.dump();
// TODO(canepat) the error code should be kServerError here: application-level errors should come from BackEnd
reply = make_json_error(request, kUnknownPayload, "unexpected exception");
reply = make_json_error(request, kServerError, "unexpected exception");
}
}

Expand Down
Loading

0 comments on commit 6e83c0e

Please sign in to comment.