Add util::ResultPtr class #26022

pull ryanofsky wants to merge 11 commits into bitcoin:master from ryanofsky:pr/bresult-ptr changing 19 files +807 −199
  1. ryanofsky commented at 3:57 pm on September 6, 2022: contributor

    This is based on #25665. The non-base commits are:


    The util::ResultPtr class is a wrapper for util::Result providing syntax sugar to make it less awkward to use with returned pointers. Instead of needing to be deferenced twice with **result or (*result)->member, it only needs to be dereferenced once with *result or result->member. Also when it is used in a boolean context, instead of evaluating to true when there is no error and the pointer is null, it evaluates to false so it is straightforward to determine whether the result points to something.

    This PR is only partial a solution to #26004 because while it makes it easier to check for null pointer values, it does not make it impossible to return a null pointer value inside a successful result. It would be possible to enforce that successful results always contain non-null pointers by using a not_null type (https://github.com/bitcoin/bitcoin/issues/24423) in combination with ResultPtr, though.

  2. ryanofsky commented at 3:57 pm on September 6, 2022: contributor
    In draft state because it’s a partial solution to #26004 and could be discussed more
  3. DrahtBot commented at 11:11 pm on September 6, 2022: contributor

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

    Code Coverage & Benchmarks

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

    Reviews

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

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #34247 (security: harden CI actions and subprocess calls by RinZ27)
    • #34004 (Implementation of SwiftSync by rustaceanrob)
    • #32061 (Replace libevent with our own HTTP and socket-handling implementation by pinheadmz)
    • #31260 (scripted-diff: Type-safe settings retrieval by ryanofsky)
    • #30342 (kernel, logging: Pass Logger instances to kernel objects by ryanofsky)
    • #28690 (build: Introduce internal kernel library by sedited)
    • #19461 (multiprocess: Add bitcoin-gui -ipcconnect option by ryanofsky)
    • #19460 (multiprocess: Add bitcoin-wallet -ipcconnect option by ryanofsky)
    • #10102 (Multiprocess bitcoin by ryanofsky)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

    LLM Linter (✨ experimental)

    Possible typos and grammar issues:

    • “helper functions types that can be used with util::Result class to for dealing with error and warning messages.” -> “helper function types that can be used with the util::Result class for dealing with error and warning messages.” [Duplicate/misplaced “to”/wrong pluralization makes the sentence ungrammatical and hard to parse.]

    • “allowing each to be understood to changed more easily.” -> “allowing each to be understood or changed more easily.” [“to changed” is ungrammatical; likely intended “to be changed” or “or changed”.]

    • “Helper function to join messages in space separated string.” -> “Helper function to join messages in a space-separated string.” [Missing article and hyphenation; current form is grammatically incorrect.]

    • “Join error and warning messages in a space separated string.” -> “Join error and warning messages in a space-separated string.” [Same hyphenation/article issue as above.]

    • “The Result class is superset of std::expected” -> “The Result class is a superset of std::expected” [Missing article “a” makes the phrase ungrammatical.]

    2026-01-17

  4. DrahtBot added the label Needs rebase on Sep 19, 2022
  5. ryanofsky force-pushed on Sep 20, 2022
  6. ryanofsky commented at 6:28 pm on September 20, 2022: contributor
    Rebased 4b8ee99dea4d990ac21dd6074a15511bc7842a8e -> 123788cf6dd74510e2a5b4ea3c566dc512a871ef (pr/bresult-ptr.1 -> pr/bresult-ptr.2, compare) due to conflict with #26005
  7. DrahtBot removed the label Needs rebase on Sep 20, 2022
  8. DrahtBot added the label CI failed on May 30, 2023
  9. DrahtBot removed the label CI failed on May 31, 2023
  10. DrahtBot added the label Needs rebase on Oct 24, 2023
  11. ryanofsky force-pushed on Oct 26, 2023
  12. DrahtBot removed the label Needs rebase on Oct 26, 2023
  13. DrahtBot added the label CI failed on Jan 14, 2024
  14. ryanofsky force-pushed on Feb 21, 2024
  15. ryanofsky commented at 11:29 pm on February 21, 2024: contributor

    Rebased a1dddc5a2a86908d9ea677875ad67a79d2c71d14 -> 8ecac0885ef5b6fc2313cd2f8dfb48c10a05db27 (pr/bresult-ptr.3 -> pr/bresult-ptr.4, compare) on top of #25665.

    I also rewrote the commit and PR description. I think this is in a good state to review, despite being based on another PR.

  16. DrahtBot removed the label CI failed on Feb 22, 2024
  17. DrahtBot added the label Needs rebase on Apr 30, 2024
  18. ryanofsky force-pushed on May 1, 2024
  19. ryanofsky commented at 5:56 pm on May 1, 2024: contributor
    Rebased 8ecac0885ef5b6fc2313cd2f8dfb48c10a05db27 -> 9f58eb795ec5592c59f9af3269f004e589a2368f (pr/bresult-ptr.4 -> pr/bresult-ptr.5, compare) on top of latest #25665 (no other changes)
  20. DrahtBot removed the label Needs rebase on May 1, 2024
  21. DrahtBot added the label Needs rebase on May 20, 2024
  22. ryanofsky force-pushed on Jun 17, 2024
  23. DrahtBot removed the label Needs rebase on Jun 17, 2024
  24. DrahtBot added the label Needs rebase on Jul 2, 2024
  25. ryanofsky force-pushed on Jul 18, 2024
  26. DrahtBot commented at 10:16 pm on July 18, 2024: contributor

    🚧 At least one of the CI tasks failed. Debug: https://github.com/bitcoin/bitcoin/runs/27633993409

    Make sure to run all tests locally, according to the documentation.

    The failure may 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.

  27. DrahtBot added the label CI failed on Jul 18, 2024
  28. DrahtBot removed the label Needs rebase on Jul 18, 2024
  29. DrahtBot removed the label CI failed on Jul 19, 2024
  30. hebasto added the label Needs CMake port on Aug 16, 2024
  31. DrahtBot commented at 5:21 am on August 29, 2024: contributor

    🚧 At least one of the CI tasks failed. Debug: https://github.com/bitcoin/bitcoin/runs/27663380898

    Make sure to run all tests locally, according to the documentation.

    The failure may 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.

  32. DrahtBot added the label CI failed on Aug 29, 2024
  33. maflcko removed the label Needs CMake port on Aug 29, 2024
  34. DrahtBot added the label Needs rebase on Sep 2, 2024
  35. ryanofsky force-pushed on Nov 4, 2024
  36. ryanofsky commented at 1:34 pm on November 4, 2024: contributor

    Rebased 5f6f91c5fd848fecdc71db25ce1c5ddbedc78f29 -> c7e73097f4a8336e23d098c2fb4296319aba318e (pr/bresult-ptr.8 -> pr/bresult-ptr.9, compare) on top of updated base PR (no changes or conflicts) Rebased c7e73097f4a8336e23d098c2fb4296319aba318e -> f8254e78c140f5756fbd981994d17f6a91ee027b (pr/bresult-ptr.9 -> pr/bresult-ptr.10, compare) on top of updated base PR (no changes or conflicts) Rebased f8254e78c140f5756fbd981994d17f6a91ee027b -> f44cb2416fe98a6ffafba2b37ee8e1a18b731a1f (pr/bresult-ptr.10 -> pr/bresult-ptr.11, compare) on top of updated base PR (no changes or conflicts) Rebased f44cb2416fe98a6ffafba2b37ee8e1a18b731a1f -> 06512c44b6264f4ece4108dfcb572c0a90ec55b9 (pr/bresult-ptr.11 -> pr/bresult-ptr.12, compare) due to silent conflict with #31061

    Rebased 06512c44b6264f4ece4108dfcb572c0a90ec55b9 -> 5b8b9c5cd7662b85d5a7474d08f1a14d0ce1ad0f (pr/bresult-ptr.12 -> pr/bresult-ptr.13, compare)

    Rebased 5b8b9c5cd7662b85d5a7474d08f1a14d0ce1ad0f -> 6efb6d865e90ff346c33fc39dc5e28a1192b3d12 (pr/bresult-ptr.13 -> pr/bresult-ptr.14, compare) due to conflict with #30595

    Rebased 6efb6d865e90ff346c33fc39dc5e28a1192b3d12 -> f8e431238504ce959528eb51f2855939ae42a431 (pr/bresult-ptr.14 -> pr/bresult-ptr.15, compare)

    Rebased f8e431238504ce959528eb51f2855939ae42a431 -> cf734e5b4778bbcbe01276f97d57e3941581535b (pr/bresult-ptr.15 -> pr/bresult-ptr.16, compare)

    Rebased cf734e5b4778bbcbe01276f97d57e3941581535b -> 8ef747c80fc3e39ecb2bb5856a489cbfc5737f48 (pr/bresult-ptr.16 -> pr/bresult-ptr.17, compare) on top of #25665 pr/bresult2.73

  37. DrahtBot removed the label Needs rebase on Nov 4, 2024
  38. DrahtBot removed the label CI failed on Nov 4, 2024
  39. DrahtBot added the label Needs rebase on Dec 5, 2024
  40. ryanofsky force-pushed on Dec 6, 2024
  41. ryanofsky force-pushed on Dec 6, 2024
  42. DrahtBot removed the label Needs rebase on Dec 6, 2024
  43. DrahtBot added the label Needs rebase on Jan 17, 2025
  44. ryanofsky force-pushed on Mar 12, 2025
  45. DrahtBot removed the label Needs rebase on Mar 12, 2025
  46. DrahtBot added the label CI failed on May 19, 2025
  47. DrahtBot removed the label CI failed on May 22, 2025
  48. DrahtBot added the label Needs rebase on Jul 30, 2025
  49. ryanofsky force-pushed on Aug 1, 2025
  50. DrahtBot removed the label Needs rebase on Aug 2, 2025
  51. DrahtBot added the label Needs rebase on Nov 4, 2025
  52. ryanofsky force-pushed on Nov 11, 2025
  53. DrahtBot removed the label Needs rebase on Nov 11, 2025
  54. DrahtBot added the label Needs rebase on Dec 9, 2025
  55. ryanofsky force-pushed on Dec 12, 2025
  56. DrahtBot removed the label Needs rebase on Dec 12, 2025
  57. DrahtBot added the label CI failed on Dec 12, 2025
  58. DrahtBot commented at 6:03 pm on December 12, 2025: contributor

    🚧 At least one of the CI tasks failed. Task lint: https://github.com/bitcoin/bitcoin/actions/runs/20166560660/job/57895210798 LLM reason (✨ experimental): Lint failure: a new circular dependency between util::messages and util::result triggered by lint-circular-dependencies.py causing the CI to fail.

    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.

  59. DrahtBot added the label Needs rebase on Dec 15, 2025
  60. ryanofsky force-pushed on Dec 16, 2025
  61. DrahtBot removed the label Needs rebase on Dec 16, 2025
  62. DrahtBot removed the label CI failed on Dec 16, 2025
  63. DrahtBot added the label Needs rebase on Dec 16, 2025
  64. refactor: Add util::Result failure values
    Add util::Result support for returning more error information. For better error
    handling, adds the ability to return a value on failure, not just a value on
    success. This is a key missing feature that made the result class not useful
    for functions like LoadChainstate() which produce different errors that need to
    be handled differently.
    
    This change also makes some more minor improvements:
    
    - Smaller type size. On 64-bit platforms, util::Result<int> is 16 bytes, and
      util::Result<void> is 8 bytes. Previously util::Result<int> and
      util::Result<void> were 72 bytes.
    
    - More documentation and tests.
    b4535ec0a0
  65. wallet: fix clang-tidy warning performance-no-automatic-move
    Previous commit causes the warning to be triggered, but the suboptimal return
    from const statement was added earlier in 517e204bacd9d.
    
    Warning was causing CI failure https://cirrus-ci.com/task/6159914970644480
    173c0eb043
  66. refactor: Add util::Result::Update() method
    Add util::Result Update method to make it possible to change the value of an
    existing Result object. This will be useful for functions that can return
    multiple error and warning messages, and want to be able to change the result
    value while keeping existing messages.
    db27f8bc0f
  67. refactor: Use util::Result class in LoadChainstate and VerifyLoadedChainstate 0263614685
  68. refactor: Add util::Result multiple error and warning messages
    Add util::Result support for returning warning messages and multiple errors,
    not just a single error string. This provides a way for functions to report
    errors and warnings in a standard way, and simplifies interfaces.
    
    The functionality is unit tested here, and put to use in followup PR
    https://github.com/bitcoin/bitcoin/pull/25722
    873582ff04
  69. test: add static test for util::Result memory usage
    Suggested by Martin Leitner-Ankerl <martin.ankerl@gmail.com>
    https://github.com/bitcoin/bitcoin/pull/25722#discussion_r1174298529
    
    Co-authored-by: Martin Leitner-Ankerl <martin.ankerl@gmail.com>
    339f0d9f76
  70. ci: Avoid -Wno-error=maybe-uninitialized false positives
    Avoid false positive maybe-uninitialized errors in
    00_setup_env_native_fuzz_with_valgrind CI jobs. Similar errors also happen in
    00_setup_env_arm and 00_setup_env_win64 jobs.
    
    Problem was pointed out and fix was suggested by maflcko in
    https://github.com/bitcoin/bitcoin/pull/25665#issuecomment-3457573218
    
    CI errors look like:
    https://github.com/bitcoin/bitcoin/actions/runs/18881332233/job/53885646274?pr=25665
    
    /home/admin/actions-runner/_work/_temp/src/wallet/test/util.cpp: In function ‘wallet::DescriptorScriptPubKeyMan* wallet::CreateDescriptor(CWallet&, const std::string&, bool)’:
    /home/admin/actions-runner/_work/_temp/src/wallet/test/util.cpp:213:29: error: ‘*(const std::reference_wrapper<wallet::DescriptorScriptPubKeyMan>*)((char*)&spkm + offsetof(util::Result<std::reference_wrapper<wallet::DescriptorScriptPubKeyMan>, void, util::Messages>,util::Result<std::reference_wrapper<wallet::DescriptorScriptPubKeyMan>, void, util::Messages>::<unnamed>.util::detail::SuccessHolder<std::reference_wrapper<wallet::DescriptorScriptPubKeyMan>, void, util::Messages>::<unnamed>)).std::reference_wrapper<wallet::DescriptorScriptPubKeyMan>::_M_data’ may be used uninitialized [-Werror=maybe-uninitialized]
      213 |     return &spkm.value().get();
          |             ~~~~~~~~~~~~~~~~^~
    /home/admin/actions-runner/_work/_temp/src/wallet/test/util.cpp:212:10: note: ‘*(const std::reference_wrapper<wallet::DescriptorScriptPubKeyMan>*)((char*)&spkm + offsetof(util::Result<std::reference_wrapper<wallet::DescriptorScriptPubKeyMan>, void, util::Messages>,util::Result<std::reference_wrapper<wallet::DescriptorScriptPubKeyMan>, void, util::Messages>::<unnamed>.util::detail::SuccessHolder<std::reference_wrapper<wallet::DescriptorScriptPubKeyMan>, void, util::Messages>::<unnamed>)).std::reference_wrapper<wallet::DescriptorScriptPubKeyMan>::_M_data’ was declared here
      212 |     auto spkm = Assert(keystore.AddWalletDescriptor(w_desc, keys,/*label=*/"", /*internal=*/false));
          |          ^~~~
    a3c37e68a7
  71. Merge branch 'pr/bresult2' into pr/bresult-ptr 23cd78342f
  72. Add util::ResultPtr class
    The util::ResultPtr class is a wrapper for util::Result providing syntax sugar
    to make it less awkward to use with returned pointers. Instead of needing to be
    deferenced twice with **result or (*result)->member, it only needs to be
    dereferenced once with *result or result->member. Also when it is used in a
    boolean context, instead of evaluating to true when there is no error and the
    pointer is null, it evaluates to false so it is straightforward to determine
    whether the result points to something.
    
    This PR is only partial a solution to #26004 because while it makes it easier
    to check for null pointer values, it does not make it impossible to return a
    null pointer value inside a successful result. It would be possible to enforce
    that successful results always contain non-null pointers by using a not_null
    type (https://github.com/bitcoin/bitcoin/issues/24423) in combination with
    ResultPtr, though.
    5142f017ea
  73. Use ResultPtr<unique_ptr> instead of Result<unique_ptr> 8ef747c80f
  74. test-each-commit: Increase fetch depth
    Needed due to base PR, can be dropped before merge
    618ea16aff
  75. ryanofsky force-pushed on Jan 17, 2026
  76. DrahtBot removed the label Needs rebase on Jan 17, 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-01-21 06:13 UTC

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