Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rpcdaemon: enum values for protocol error codes #2146

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading