rpc: Return the right RPCErrorCode more consistently #36826

pull maflcko wants to merge 8 commits into bitcoin:master from maflcko:2611-rpc-errors-consistent changing 20 files +142 −93
  1. maflcko commented at 1:20 PM on November 10, 2026: member

    Currently, rpc code may return the wrong RPCErrorCode. This is perfectly fine, because they should be hit rarely in production.

    However, it could be good to be self-consistent. (Otherwise, we could just remove the different error codes and return a single one)

    So fix a few error codes:

    • An integral out-of-range is now RPC_TYPE_ERROR, not RPC_MISC_ERROR
    • Some invalid args are now RPC_INVALID_PARAMETER
    • Some transient issues or user-config issues are now RPC_MISC_ERROR
    • Finally, RPC_INTERNAL_ERROR is reserved for internal bugs or internal corruption
  2. rpc: For int out-of-range, throw RPC_TYPE_ERROR (-3), not RPC_MISC_ERROR (-1)
    This follows the other json type errors from commit
    55566630c60d23993a52ed54c95e7891f4588d57.
    faf981a272
  3. doc: Use proper doxygen groups for RPCErrorCode
    Previously, the group comment was incorrectly attached to the first item
    in the group.
    fa598e9b39
  4. rpc: Use RPC_INVALID_PARAMETER for invalid args
    This follows all other uses of the constant, like:
    
    throw JSONRPCError(RPC_INVALID_PARAMETER, "The PSBT version can only be 2 or 0");
    fad9b5066e
  5. rpc: Use RPC_INTERNAL_ERROR for unreachable internal error only
    Also, switch the two violations to use RPC_MISC_ERROR (-1):
    
    * coinstatsindex still syncing
    * disabled fee estimation
    
    This follows other intermittent or user-config errors, such as:
    
    * throw JSONRPCError(RPC_MISC_ERROR, "The mempool was not loaded yet");
    * throw JSONRPCError(RPC_MISC_ERROR, "Can't rescan beyond pruned data...");
    fa17d12195
  6. rpc: refactor: Use explicit RPC_MISC_ERROR
    This refactor does not change any behavior because a runtime_error
    exception is currently mapped to RPC_MISC_ERROR.
    
    Though, using explicit RPC_MISC_ERROR is clearer and follows other
    intermittent or user-config errors.
    eeeeb4cf64
  7. rpc: refactor: Explicitly throw rpc help as RPC_MISC_ERROR (-1)
    This refactor does not change any behavior.
    fa9afca584
  8. rpc: refactor: Throw RPC_MISC_ERROR explicitly on external signer errors
    This refactor does not change any behavior because a runtime_error
    exception is currently mapped to RPC_MISC_ERROR.
    
    Though, using explicit RPC_MISC_ERROR is clearer and follows other
    intermittent or user-config errors.
    fa9696eaff
  9. rpc: Use RPC_INTERNAL_ERROR for internal errors
    Internal errors or bugs should never happen, so this should not change
    any production behavior. Though, using RPC_INTERNAL_ERROR is more
    consistent.
    fa6e112c1a
  10. DrahtBot added the label RPC/REST/ZMQ on Nov 10, 2026
  11. DrahtBot commented at 1:20 PM on November 10, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--006a51241073e994b41acfe9ec718e94-->

    External sites

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process. A summary of reviews will appear here.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

    LLM Linter (✨ experimental)

    Possible places where comparison-specific test macros should replace generic comparisons:

    • src/univalue/test/object.cpp: BOOST_CHECK_THROW(v_negative.getInt<uint8_t>(), UniValue::type_error) → Prefer BOOST_CHECK_EXCEPTION with a check for the expected failure message, "JSON integer out of range".
    • src/univalue/test/object.cpp: BOOST_CHECK_THROW(v2.getInt<int>(), UniValue::type_error) → Prefer BOOST_CHECK_EXCEPTION checking the expected type-error message.
    • src/univalue/test/object.cpp: BOOST_CHECK_THROW(v3.getInt<int64_t>(), UniValue::type_error) → Prefer BOOST_CHECK_EXCEPTION checking "JSON integer out of range".
    • src/univalue/test/object.cpp: BOOST_CHECK_THROW(v4.getInt<int>(), UniValue::type_error) → Prefer BOOST_CHECK_EXCEPTION checking "JSON integer out of range".
    • src/univalue/test/object.cpp: BOOST_CHECK_THROW(vals[0].getInt<int>(), UniValue::type_error) → Prefer BOOST_CHECK_EXCEPTION checking the expected type-error message.

    <sup>2026-11-10 13:21:11</sup>

  12. DrahtBot added the label CI failed on Nov 10, 2026

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-11-10 20:51 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me