From 59a397c4b1fca3ac25211e5153bfca5b4cb146f7 Mon Sep 17 00:00:00 2001 From: lupin012 <58134934+lupin012@users.noreply.github.com> Date: Mon, 16 Sep 2024 10:39:13 +0200 Subject: [PATCH] rpcdaemon: trap einval exception to manage block not found (#2352) --- silkworm/rpc/commands/erigon_api.cpp | 4 ++++ silkworm/rpc/commands/eth_api.cpp | 2 ++ 2 files changed, 6 insertions(+) diff --git a/silkworm/rpc/commands/erigon_api.cpp b/silkworm/rpc/commands/erigon_api.cpp index 176fedd0c3..4cb4188e9d 100644 --- a/silkworm/rpc/commands/erigon_api.cpp +++ b/silkworm/rpc/commands/erigon_api.cpp @@ -256,6 +256,8 @@ Task ErigonRpcApi::handle_erigon_get_header_by_hash(const nlohmann::json& } else { reply = make_json_content(request, *header); } + } catch (const std::invalid_argument& iv) { + reply = make_json_error(request, kServerError, "block header not found: 0x" + silkworm::to_hex(block_hash)); } catch (const std::exception& e) { SILK_ERROR << "exception: " << e.what() << " processing request: " << request.dump(); reply = make_json_error(request, kInternalError, e.what()); @@ -423,6 +425,8 @@ Task ErigonRpcApi::handle_erigon_get_logs_by_hash(const nlohmann::json& re SILK_DEBUG << "logs.size(): " << logs.size(); reply = make_json_content(request, logs); + } catch (const std::invalid_argument& iv) { + reply = make_json_content(request, nullptr); } catch (const std::exception& e) { SILK_ERROR << "exception: " << e.what() << " processing request: " << request.dump(); reply = make_json_error(request, kInternalError, e.what()); diff --git a/silkworm/rpc/commands/eth_api.cpp b/silkworm/rpc/commands/eth_api.cpp index 25cb2093c9..c74b36a0d0 100644 --- a/silkworm/rpc/commands/eth_api.cpp +++ b/silkworm/rpc/commands/eth_api.cpp @@ -464,6 +464,8 @@ Task EthereumRpcApi::handle_eth_get_uncle_count_by_block_hash(const nlohma const auto ommers = block_with_hash->block.ommers.size(); reply = make_json_content(request, to_quantity(ommers)); } + } catch (const std::invalid_argument& iv) { + reply = make_json_content(request, nullptr); } catch (const std::exception& e) { SILK_ERROR << "exception: " << e.what() << " processing request: " << request.dump(); reply = make_json_error(request, kInternalError, e.what());