rpc, wallet: fix invalid JSON in HelpExampleRpc curl examples #35868

pull GuTS805 wants to merge 1 commits into bitcoin:master from GuTS805:fix-helpexamplerpc-json changing 9 files +26 −17
  1. GuTS805 commented at 1:16 AM on August 3, 2026: none

    Several HelpExampleRpc call sites reused CLI-style argument strings verbatim instead of valid JSON — missing commas, bare unquoted words, or single backslashes that are not valid JSON escapes. As a result the documented curl command for 13 RPCs (getblockfrompeer, addnode, addconnection, sendmsgtopeer, restorewallet, getmempoolcluster, importmempool, getindexinfo, listlabels, unloadwallet, createwalletdescriptor, addhdkey, loadwallet) fails to parse as JSON if copy-pasted as-is. Also fixes a stray trailing quote in the restorewallet named-argument examples.

    This was previously raised in #31275, which sipa confirmed at runtime by adding a UniValue::read check, but that PR was closed unmerged. Since then two more examples broke the same way (getmempoolcluster, addhdkey), which is why this adds a permanent regression check to rpc_help.py::dump_help() instead of just fixing the current list.

    Fixes #35864.

    First commit adds the regression check (would fail on current master), second commit fixes the 13 examples so the check passes.

  2. DrahtBot commented at 1:16 AM on August 3, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/35868.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

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

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    No conflicts as of last run.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  3. in src/wallet/rpc/backup.cpp:628 in 88d9e18db7
     624 | @@ -625,9 +625,9 @@ RPCMethod restorewallet()
     625 |          },
     626 |          RPCExamples{
     627 |              HelpExampleCli("restorewallet", "\"testwallet\" \"home\\backups\\backup-file.bak\"")
     628 | -            + HelpExampleRpc("restorewallet", "\"testwallet\" \"home\\backups\\backup-file.bak\"")
     629 | -            + HelpExampleCliNamed("restorewallet", {{"wallet_name", "testwallet"}, {"backup_file", "home\\backups\\backup-file.bak\""}, {"load_on_startup", true}})
     630 | -            + HelpExampleRpcNamed("restorewallet", {{"wallet_name", "testwallet"}, {"backup_file", "home\\backups\\backup-file.bak\""}, {"load_on_startup", true}})
     631 | +            + HelpExampleRpc("restorewallet", "\"testwallet\", \"home\\\\backups\\\\backup-file.bak\"")
    


    maflcko commented at 6:51 AM on August 3, 2026:

    I don't think the \\b was caught (or will be caught in the future) as an issue by the json-parse test?

    In any place where manual escaping is needed, it seems easier to just use raw strings directly:

    R"("testwallet", "home\\backups\\backup-file.bak")";
    
  4. GuTS805 force-pushed on Aug 3, 2026
  5. GuTS805 commented at 7:30 AM on August 3, 2026: none

    Good catch, thanks. You're right that \b would silently pass the json.loads() check since it's a technically-valid (but wrong) JSON escape. Switched both this one and the loadwallet example to raw string literals as suggested, pushed in the latest commit.

  6. in src/wallet/rpc/wallet.cpp:864 in 67d7b0e16d
     860 | @@ -861,7 +861,7 @@ RPCMethod addhdkey()
     861 |              },
     862 |          },
     863 |          RPCExamples{
     864 | -            HelpExampleCli("addhdkey", "xprv") + HelpExampleRpc("addhdkey", "xprv")
     865 | +            HelpExampleCli("addhdkey", "xprv") + HelpExampleRpc("addhdkey", "\"xprv\"")
    


    maflcko commented at 8:01 AM on August 3, 2026:

    I'd say generally it seems best to not spend time on manually escaping all quotes and backslashes in all those strings after a test failure.

    It seems better to use r-strings like R"("xprv")" consistently (at least for all lines required to be touched in this pull anyway)?

  7. GuTS805 force-pushed on Aug 3, 2026
  8. GuTS805 force-pushed on Aug 3, 2026
  9. GuTS805 commented at 10:33 AM on August 3, 2026: none

    Pushed an update addressing the review feedback and the CI failures from the previous run:

    • Converted all lines touched in this PR to raw string literals for consistency (per the suggestion above), avoiding manual quote/backslash escaping.
    • While investigating the CI failure, found one more pre-existing bug of the same class that my earlier scan had missed: listunspent's example (src/wallet/rpc/coins.cpp:517) was missing a comma between 9999999 and the addresses array, since it's built via string concatenation with EXAMPLE_ADDRESS rather than a plain literal. Fixed in this update.
    • Reordered the two commits (fix first, test second), since the ci-test-each-commit job runs the full test suite standalone on every commit, and the previous test-then-fix ordering was correctly failing on the intermediate ancestor commit.

    All 154 HelpExampleRpc call sites in the codebase now produce valid JSON (verified locally); the one remaining call site not covered is an intentional fuzz-harness invocation with random input (src/test/fuzz/string.cpp), which is out of scope.

  10. DrahtBot added the label CI failed on Aug 3, 2026
  11. maflcko commented at 12:09 PM on August 3, 2026: member
  12. rpc, wallet, test: fix invalid JSON in HelpExampleRpc curl examples
    Several HelpExampleRpc call sites reused CLI-style argument strings
    verbatim (missing commas, bare unquoted words, or single backslashes
    that are not valid JSON escapes), producing curl examples that fail
    JSON parsing as documented. Also fixes a stray trailing quote in the
    restorewallet named-argument examples, and a missing comma in the
    listunspent example.
    
    Lines touched are converted to raw string literals throughout, for
    consistency and to avoid manual quote/backslash escaping.
    
    Adds a regression check to rpc_help.py::dump_help() so this class of
    bug can't silently reappear.
    d831908a40
  13. GuTS805 force-pushed on Aug 3, 2026
  14. GuTS805 commented at 3:32 PM on August 3, 2026: none

    Done, squashed into a single commit.

  15. GuTS805 commented at 11:03 AM on August 4, 2026: none

    The 2 remaining failures (NetBSD Cross, riscv32 bare metal) look unrelated to this change. NetBSD Cross fails on a 404 from cdn.netbsd.org fetching the SDK tarball, and riscv32 fails during the GCC mirror submodule clone with no clear error, before any of our code is even built/tested. Happy to have these re-run if a maintainer can trigger that.

  16. maflcko closed this on Aug 4, 2026

  17. maflcko reopened this on Aug 4, 2026

  18. DrahtBot removed the label CI failed on Aug 4, 2026
  19. DrahtBot added the label CI failed on Aug 6, 2026
  20. DrahtBot commented at 12:05 AM on August 6, 2026: contributor

    <!--85328a0da195eb286784d51f73fa0af9-->

    🚧 At least one of the CI tasks failed. <sub>Task riscv32 bare metal, static libbitcoin_consensus: https://github.com/bitcoin/bitcoin/actions/runs/30805638058/job/92449829226</sub> <sub>LLM reason (✨ experimental): CI failed because submodule cloning of https://sourceware.org/git/binutils-gdb.git was rate-limited (HTTP 429) and exited with code 2.</sub>

    <details><summary>Hints</summary>

    Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example:

    • Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch.

    • A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test.

    • An intermittent issue.

    Leave a comment here, if you need help tracking down a confusing failure.

    </details>

  21. DrahtBot removed the label CI failed on Aug 7, 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-08-10 11:50 UTC

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