Skip to content

wallet: Introduce WalletError with machine-readable error code - #35690

Merged
sedited merged 1 commit into
bitcoin:masterfrom
pseudoramdom:wallet-error-type
Jul 13, 2026
Merged

sedited merged 1 commit into
bitcoin:masterfrom
pseudoramdom:wallet-error-type

Conversation

@pseudoramdom

Copy link
Copy Markdown
Contributor

Per discussion in #35436 (comment), WalletError is split out so that it can be reused by multiple wallet interface changes (#34861 in particular)


Introduce a wallet::WalletError, a generic wallet-layer error type that contains

  • a machine-readable WalletErrorCode for programmatic handling
  • a translated user-facing bilingual_str message

The initial enum is intentionally small. WALLET_ERROR is used for generic failures that callers should display to the user. The intention is to have more specific codes only when the callers can handle the condition differently.

@DrahtBot DrahtBot added the Wallet label Jul 9, 2026
@DrahtBot

DrahtBot commented Jul 9, 2026 •

Copy link
Copy Markdown
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/35690.

Reviews

See the guideline and AI policy for information on the review process.

Type Reviewers
ACK achow101, polespinasa, davidgumberg

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #34861 (wallet: Add importdescriptors interface by polespinasa)
  • #34617 (fees: wallet: remove block policy fee estimator internals from wallet by ismaelsadeeq)
  • #34075 (fees: Introduce Mempool Based Fee Estimation to reduce overestimation by ismaelsadeeq)

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.

@pseudoramdom

Copy link
Copy Markdown
Contributor Author

cc @polespinasa

@polespinasa

polespinasa commented Jul 9, 2026 •

Copy link
Copy Markdown
Member

Thanks for this :)

So bringing back my comment #35436 (comment)

Maybe not adding all of them as I initially suggested, but for example #34861 needs, apart from the ones this PR adds:

enum class WalletErrorCode {
        INVALID_DESCRIPTOR,
        INVALID_PARAMETER,
        MISC_ERROR
};

Are we open to add those to this enum, even if some like INVALID_DESCRIPTOR are not as much generic as others?
If we don't then we need multiple structs to handle different error codes which adds a lot of complexity.

@achow101

achow101 commented Jul 9, 2026

Copy link
Copy Markdown
Member

Are we open to add those to this enum, even if some like INVALID_DESCRIPTOR are not as much generic as others?
If we don't then we need multiple structs to handle different error codes which adds a lot of complexity.

Ugh, I don't like either approach. Preferably parameter validation should occur before calling the interface functions so that we don't need INVALID_DESCRIPTOR and INVALID_PARAMETER. MISC_ERROR is only returned by rescan issues, so those could possibly be a more specific enum for rescan failure that I guess could be actionable by callers.

@polespinasa

Copy link
Copy Markdown
Member

Preferably parameter validation should occur before calling the interface functions so that we don't need INVALID_DESCRIPTOR and INVALID_PARAMETER

That would mean duplicating a lot of code. For example, we throw INVALID_DESCRIPTOR in multiple occasions because things like "Range should not be specified for an un-ranged descriptor", "Cannot have multipath descriptor while also specifying 'internal'", same for INVALID_PARAMETER, which is used for things like Ranged descriptors should not have a label or Active descriptors must be ranged.

I am not sure duplicating all those checks is a good idea.

so those could possibly be a more specific enum for rescan failure that I guess could be actionable by callers.

Care to propose pseudo-code? I am not sure I follow you.

@achow101

achow101 commented Jul 9, 2026

Copy link
Copy Markdown
Member

That would mean duplicating a lot of code. For example, we throw INVALID_DESCRIPTOR in multiple occasions because things like "Range should not be specified for an un-ranged descriptor", "Cannot have multipath descriptor while also specifying 'internal'", same for INVALID_PARAMETER, which is used for things like Ranged descriptors should not have a label or Active descriptors must be ranged.

I am not sure duplicating all those checks is a good idea.

I guess a single INVALID_PARAMETER enum would also be fine. I don't really want to be getting that granular about how invalid the parameters are.

so those could possibly be a more specific enum for rescan failure that I guess could be actionable by callers.

Care to propose pseudo-code? I am not sure I follow you.

Instead of MISC_ERROR, we could have RESCAN_FAILURE as that is what the importdescriptors reports MISC_ERROR for anyways.

@davidgumberg

Copy link
Copy Markdown
Contributor

Instead of MISC_ERROR, we could have RESCAN_FAILURE as that is what the importdescriptors reports MISC_ERROR for anyways.

Sorry I'm not sure I follow why these all can't fall under MISC_ERROR since it's just an error message that gets printed for the user in both cases, right? Or is there something different that the caller does for each error?

@davidgumberg

Copy link
Copy Markdown
Contributor

ACK 1526321

It's a bit weird to add stub code like this, but it makes sense since otherwise there is a bit of awkwardness with both #35436 and #34681 needing this, merging this so both of those can be reviewed in parallel seems fine.

It makes sense to me to provide machine-readable error codes for cases where there is something interesting the caller can do with the error code. For now just a wallet locked and an unlock error code, seem reasonable, and we can probably bikeshed what other specific error codes should or shouldn't get added in the PR's where interfaces are being added that want them.

@pseudoramdom

Copy link
Copy Markdown
Contributor Author

Force pushed to c6ed33f001f36ebd91298792e3802d63aea813c5 to address comment in #35436 (comment) to remove WALLET_ prefix from the error cases.

@pseudoramdom

Copy link
Copy Markdown
Contributor Author

we can probably bikeshed what other specific error codes should or shouldn't get added in the PR's where interfaces are being added that want them

Agree.

Comment thread src/wallet/types.h Resolved
@pseudoramdom

pseudoramdom commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor Author

Force pushed to d4ebd859023a78dd14d81d43555ae3d2a102c104 a8223bb to address #35690 (comment) and use PascalCase

Introduce WalletError as a generic wallet-layer error type that can carry a machine-readable WalletErrorCode and a translated user-facing message.

The WalletErrorCode::GenericError code is intended for failures that callers should only display to the user. More specific codes should only be added when callers can handle the condition differently.
@polespinasa

polespinasa commented Jul 10, 2026 •

Copy link
Copy Markdown
Member

I guess a single INVALID_PARAMETER enum would also be fine. I don't really want to be getting that granular about how invalid the parameters are.

How do you translate them if we use the same INVALID_PARAMETER for different codes?
This only matter for not breaking the current RPC obviously, for new interfaces it does not matter at all.

@achow101

Copy link
Copy Markdown
Member

How do you translate them if we use the same INVALID_PARAMETER for different codes?

I would be okay with changing the error codes.

@achow101

Copy link
Copy Markdown
Member

ACK a8223bb

@DrahtBot
DrahtBot requested a review from davidgumberg July 10, 2026 21:00
@polespinasa

Copy link
Copy Markdown
Member

How do you translate them if we use the same INVALID_PARAMETER for different codes?

I would be okay with changing the error codes.

Let's discuss this in #34861

@polespinasa polespinasa left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK a8223bb

@davidgumberg

Copy link
Copy Markdown
Contributor

ACK a8223bb

@sedited
sedited merged commit fe1cb6e into bitcoin:master Jul 13, 2026
28 checks passed
alexanderwiederin added a commit to alexanderwiederin/rust-bitcoinkernel that referenced this pull request Jul 14, 2026
…4e48e968a

114e48e968a kernel: Add script tracer
54e1a95a12e Merge bitcoin/bitcoin#35719: ci: disable Qt build in OpenBSD cross job
b0e09511586 ci: disable Qt build in OpenBSD cross job
734c34bafda Merge bitcoin/bitcoin#35427: depends: Build `qt` and `qrencode` packages on OpenBSD
ee61b11a9e7 Merge bitcoin/bitcoin#35200: node: smooth oversized `dbcache` warnings
e3554bf361f Merge bitcoin/bitcoin#35579: wallet: reserve walletrescan before checking wallet is at the tip
11ae4265522 Merge bitcoin/bitcoin#35715: cmake: Fix WITH_EXTERNAL_LIBMULTIPROCESS + BUILD_FUZZ_BINARY
e544413c0de Merge bitcoin/bitcoin#32763: wallet: Replace CWalletTx::mapValue and vOrderForm with explicit class members
fe1cb6e40d7 Merge bitcoin/bitcoin#35690: wallet: Introduce WalletError with machine-readable error code
441f3114f57 Merge bitcoin/bitcoin#35659: Clarify supported *BSD releases and drop outdated workarounds
0399df827c6 Merge bitcoin/bitcoin#35708: depends: capnp 1.5.0
1ab1fdd4696 Merge bitcoin/bitcoin#35705: bench: replace CreateMockableWalletDatabase with MakeInMemoryWalletDatabase
db35b9238fc ipc # build: Fix fuzz target CMakeLists.txt for external libmultiprocess
d18fec892e2 Merge bitcoin/bitcoin#35698: doc: Update enum class constant naming style guide
a2e4cd7ad2a depends: capnp 1.5.0
7508ac319d9 bench: replace CreateMockableWalletDatabase with MakeInMemoryWalletDatabase
907e284e303 Merge bitcoin/bitcoin#35701: test: Remove `mock_process.cpp`
c8459b6bdcd Merge bitcoin/bitcoin#35568: txospenderindex: disable bloom filters to optimize disk usage
63c5f9d22c0 test: Remove `mock_process.cpp`
ef101b04a8d Merge bitcoin/bitcoin#35655: wallet: Use in-memory SQLite for temporary wallet in exportwatchonlywallet
b6becf3534c Merge bitcoin/bitcoin#35684: Update libmultiprocess subtree to add `max_connections` option
930f25050f7 Merge bitcoin/bitcoin#35700: doc: archive release notes for v29.4
9b2b3f4ec6f doc: archive release notes for v29.4
297fd1489bb Merge bitcoin/bitcoin#35412: ci: add NetBSD Clang cross job
e314869066b Merge bitcoin/bitcoin#35695: Remove myself as security contact
e3d67a5eae5 Merge bitcoin/bitcoin#35691: chainparams: delete my DNS seed
a8223bb4e62 wallet: Introduce WalletError with machine-readable error code
fad5809cb92 doc: Update enum class constant naming style guide
7d8137c1417 Merge bitcoin/bitcoin#34897: indexes: Don't commit ahead of the flushed chainstate
629df81e4c6 Remove myself as security contact
d164a043426 node: smooth oversized `-dbcache` warnings
d9080639804 chainparams: delete my DNS seed
e9ed898a0da validation: Don't use m_chain.Tip() in FlushStateToDisk
3679f1ecf5e index: Don't commit ahead of the flushed chainstate
65735728a5a index: Remove return value from Commit()
09c06960c6a validation: track last flushed block
13c02b5466d test: add test for index commits ahead of the last flushed block
c43b7a1115f ci: add netBSD cross CI job
699c21aea47 depends: add netbsd_LDFLAGS
777d23f25c7 test: add regression test for in-memory SQLiteDatabase reopen
d1e7f8c986f wallet: use in-memory SQLite for temporary wallet in exportwatchonlywallet
ee43743f126 wallet: store m_additional_flags in SQLiteDatabase to fix reopen path
a9d1b652f32 Merge commit '707d0ded84563386f770ec17970834c65f8fa938' into pr/subtree-12
707d0ded845 Squashed 'src/ipc/libmultiprocess/' changes from 16bf05dea02..28e056576a3
2bab6bc73f2 refactor: Drop support for FreeBSD < 14
91b5c8a07c6 refactor: Remove FreeBSD-specific workaround
56701ff6d5c doc: Clarify supported *BSD releases
6d0ea4cf5bd doc: add release notes
a2b1c86903a txospenderindex: disable bloom filters to optimize disk usage
fed3cf6f0ed wallet: Replace CWalletTx's vOrderForm with specific fields
4f8823e8e11 wallet: Drop vOrderForm from CommitTransaction
9e62e4b1f34 test: slow down rescaning process
a2b0bfcd854 wallet: Drop mapValue from CWalletTx
cb99864c91c wallet: Throw if unknown entry is found in mapValue
98d5cdae663 wallet: Make CWalletTx "replaces_txid" and "replaced_by_txid" member variables
7ef8a6efc2a wallet: Make CWalletTx "comment" and "to" member variables
2155e913d3e wallet: Make CWalletTx "from" and "message" member variables
c6ba98dcc8a wallet: Drop mapValue from CommitTransaction
00abb174a80 wallet: Pass comment and comment_to to CommitTransaction
1a219a37a21 wallet: Pass replaces_txid to CommitTransaction outside of mapValue
336f5a738b3 wallet: reserve walletrescan before checking wallet is at the tip
a54ec373a69 depends: Build `qt` and `qrencode` packages for OpenBSD hosts

git-subtree-dir: libbitcoinkernel-sys/bitcoin
git-subtree-split: 114e48e968a087f74c1ab611ac2a31a9266812e1
Kino1994 pushed a commit to Kino1994/bitcoin-full-history that referenced this pull request Jul 19, 2026
…ne-readable error code

f6ce25f wallet: Introduce WalletError with machine-readable error code (pseudoramdom)

Pull request description:

  Per discussion in bitcoin/bitcoin#35436 (comment), `WalletError` is split out so that it can be reused by multiple wallet interface changes (#34861 in particular)

  ----

  Introduce a `wallet::WalletError`, a generic wallet-layer error type that contains
  - a machine-readable `WalletErrorCode` for programmatic handling
  - a translated user-facing `bilingual_str` message

  The initial enum is intentionally small. `WALLET_ERROR` is used for generic failures that callers should display to the user. The intention is to have more specific codes only when the callers can handle the condition differently.

ACKs for top commit:
  achow101:
    ACK f6ce25f
  davidgumberg:
    ACK f6ce25f
  polespinasa:
    ACK f6ce25f

Tree-SHA512: 15fedf96cb5c3e8167a236bfa1a4d01d94f258a22943e53330ab432ad04a31f81f2eac8749f38390b2d34156d283d3bf76f293c640724bd0b090dc494123b230
sedited pushed a commit to sedited/rust-bitcoinkernel that referenced this pull request Jul 28, 2026
…d9ec7f3d4

70d9ec7f3d4 Merge bitcoin/bitcoin#34538: net: advertise -externalip addresses
7bff765d514 Merge bitcoin/bitcoin#35639: external_signer: validate fingerprint from enumerate response
773b1c9aa58 Merge bitcoin/bitcoin#35572: coins: make cursor iteration DB-only
8d9e4f8dbd8 Merge bitcoin/bitcoin#35633: wallet: avoid call bumpfeediscount with negative values
c4216e885a6 Merge bitcoin/bitcoin#35723: fuzz: Drop unnecessary mutexes
240d5f743aa fuzz: Drop unnecessary mutexes
cf0368fb76e Merge bitcoin/bitcoin#35720: ipc: Update libmultiprocess subtree and drop fuzz test workaround
2d4065d1fe4 Merge bitcoin/bitcoin#35718: ci: Update lint container dependencies
8d9fbf76664 Merge bitcoin/bitcoin#35380: kernel: expose witness stack and scriptSig for btck_TransactionInput
fab8eeed82c fuzz: clang-format LIMITED_WHILE
fa0d777ce2a fuzz: Clang-format LIMITED_WHILE like while
fa1a9bde5a6 fuzz: Remove unused workaround after fix in libmultiprocess byte-span serializer
fa55385ab36 fuzz: Use LIMITED_WHILE over for-loop with consumed size integral
fa911d815db Merge commit '6d5f753921578eefdd3fce64cfc8ee7951b6cbc4' into HEAD
6d5f7539215 Squashed 'src/ipc/libmultiprocess/' changes from 28e056576a..e8de5c7b68
900a7785bf5 ci: use Ubuntu 26.04 for lint container
058a73a0aea ci: use uv 11.x
14f4ddcb554 ci: mypy 2.3.0
54e1a95a12e Merge bitcoin/bitcoin#35719: ci: disable Qt build in OpenBSD cross job
b0e09511586 ci: disable Qt build in OpenBSD cross job
734c34bafda Merge bitcoin/bitcoin#35427: depends: Build `qt` and `qrencode` packages on OpenBSD
ee61b11a9e7 Merge bitcoin/bitcoin#35200: node: smooth oversized `dbcache` warnings
e3554bf361f Merge bitcoin/bitcoin#35579: wallet: reserve walletrescan before checking wallet is at the tip
11ae4265522 Merge bitcoin/bitcoin#35715: cmake: Fix WITH_EXTERNAL_LIBMULTIPROCESS + BUILD_FUZZ_BINARY
e544413c0de Merge bitcoin/bitcoin#32763: wallet: Replace CWalletTx::mapValue and vOrderForm with explicit class members
fe1cb6e40d7 Merge bitcoin/bitcoin#35690: wallet: Introduce WalletError with machine-readable error code
441f3114f57 Merge bitcoin/bitcoin#35659: Clarify supported *BSD releases and drop outdated workarounds
0399df827c6 Merge bitcoin/bitcoin#35708: depends: capnp 1.5.0
1ab1fdd4696 Merge bitcoin/bitcoin#35705: bench: replace CreateMockableWalletDatabase with MakeInMemoryWalletDatabase
db35b9238fc ipc # build: Fix fuzz target CMakeLists.txt for external libmultiprocess
d18fec892e2 Merge bitcoin/bitcoin#35698: doc: Update enum class constant naming style guide
a2e4cd7ad2a depends: capnp 1.5.0
7508ac319d9 bench: replace CreateMockableWalletDatabase with MakeInMemoryWalletDatabase
907e284e303 Merge bitcoin/bitcoin#35701: test: Remove `mock_process.cpp`
c8459b6bdcd Merge bitcoin/bitcoin#35568: txospenderindex: disable bloom filters to optimize disk usage
63c5f9d22c0 test: Remove `mock_process.cpp`
ef101b04a8d Merge bitcoin/bitcoin#35655: wallet: Use in-memory SQLite for temporary wallet in exportwatchonlywallet
b6becf3534c Merge bitcoin/bitcoin#35684: Update libmultiprocess subtree to add `max_connections` option
930f25050f7 Merge bitcoin/bitcoin#35700: doc: archive release notes for v29.4
9b2b3f4ec6f doc: archive release notes for v29.4
297fd1489bb Merge bitcoin/bitcoin#35412: ci: add NetBSD Clang cross job
e314869066b Merge bitcoin/bitcoin#35695: Remove myself as security contact
e3d67a5eae5 Merge bitcoin/bitcoin#35691: chainparams: delete my DNS seed
a8223bb4e62 wallet: Introduce WalletError with machine-readable error code
fad5809cb92 doc: Update enum class constant naming style guide
7d8137c1417 Merge bitcoin/bitcoin#34897: indexes: Don't commit ahead of the flushed chainstate
629df81e4c6 Remove myself as security contact
d164a043426 node: smooth oversized `-dbcache` warnings
d9080639804 chainparams: delete my DNS seed
e9ed898a0da validation: Don't use m_chain.Tip() in FlushStateToDisk
3679f1ecf5e index: Don't commit ahead of the flushed chainstate
65735728a5a index: Remove return value from Commit()
09c06960c6a validation: track last flushed block
13c02b5466d test: add test for index commits ahead of the last flushed block
c43b7a1115f ci: add netBSD cross CI job
699c21aea47 depends: add netbsd_LDFLAGS
777d23f25c7 test: add regression test for in-memory SQLiteDatabase reopen
d1e7f8c986f wallet: use in-memory SQLite for temporary wallet in exportwatchonlywallet
ee43743f126 wallet: store m_additional_flags in SQLiteDatabase to fix reopen path
a9d1b652f32 Merge commit '707d0ded84563386f770ec17970834c65f8fa938' into pr/subtree-12
707d0ded845 Squashed 'src/ipc/libmultiprocess/' changes from 16bf05dea02..28e056576a3
6667dc4eec7 kernel: expose scriptSig for btck_TransactionInput
e6de3a2d3c7 kernel: expose witness stack for btck_TransactionInput
3ae3a94f2bd wallet: avoid call bumpfeediscount with negative values
dab7f2c984b test: cover -externalip/onlynet interaction in functional test
657a5aa3f3d test: cover -externalip bypassing -onlynet
8c87e32bd39 net: let -externalip bypass -onlynet
f4af02e827b net: add an add_even_if_unreachable argument to AddLocal
2bab6bc73f2 refactor: Drop support for FreeBSD < 14
91b5c8a07c6 refactor: Remove FreeBSD-specific workaround
56701ff6d5c doc: Clarify supported *BSD releases
6d0ea4cf5bd doc: add release notes
a2b1c86903a txospenderindex: disable bloom filters to optimize disk usage
4c9de7d5b32 external_signer: validate fingerprint from enumerate response
fed3cf6f0ed wallet: Replace CWalletTx's vOrderForm with specific fields
4f8823e8e11 wallet: Drop vOrderForm from CommitTransaction
9e62e4b1f34 test: slow down rescaning process
a2b0bfcd854 wallet: Drop mapValue from CWalletTx
cb99864c91c wallet: Throw if unknown entry is found in mapValue
98d5cdae663 wallet: Make CWalletTx "replaces_txid" and "replaced_by_txid" member variables
7ef8a6efc2a wallet: Make CWalletTx "comment" and "to" member variables
2155e913d3e wallet: Make CWalletTx "from" and "message" member variables
c6ba98dcc8a wallet: Drop mapValue from CommitTransaction
00abb174a80 wallet: Pass comment and comment_to to CommitTransaction
1a219a37a21 wallet: Pass replaces_txid to CommitTransaction outside of mapValue
72db4accbf5 coins: drop stale cursor null checks
3d2f2d8de09 coins: pass UTXO stats view by reference
35aedb28236 coins: drop cursor from base view
c6fbe2f66cf coins: pass DB view to cursor users
336f5a738b3 wallet: reserve walletrescan before checking wallet is at the tip
a54ec373a69 depends: Build `qt` and `qrencode` packages for OpenBSD hosts

git-subtree-dir: libbitcoinkernel-sys/bitcoin
git-subtree-split: 70d9ec7f3d452789d04dce81dc02db0b3b778bb5
Kino1994 pushed a commit to Kino1994/bitcoin-full-history that referenced this pull request Aug 19, 2026
…ne-readable error code

a8223bb4e62c8facd7e99eb05221c67cdcf0b52c wallet: Introduce WalletError with machine-readable error code (pseudoramdom)

Pull request description:

  Per discussion in bitcoin/bitcoin#35436 (comment), `WalletError` is split out so that it can be reused by multiple wallet interface changes (#34861 in particular)

  ----

  Introduce a `wallet::WalletError`, a generic wallet-layer error type that contains
  - a machine-readable `WalletErrorCode` for programmatic handling
  - a translated user-facing `bilingual_str` message

  The initial enum is intentionally small. `WALLET_ERROR` is used for generic failures that callers should display to the user. The intention is to have more specific codes only when the callers can handle the condition differently.

ACKs for top commit:
  achow101:
    ACK a8223bb4e62c8facd7e99eb05221c67cdcf0b52c
  davidgumberg:
    ACK a8223bb4e62c8facd7e99eb05221c67cdcf0b52c
  polespinasa:
    ACK a8223bb4e62c8facd7e99eb05221c67cdcf0b52c

Tree-SHA512: 15fedf96cb5c3e8167a236bfa1a4d01d94f258a22943e53330ab432ad04a31f81f2eac8749f38390b2d34156d283d3bf76f293c640724bd0b090dc494123b230
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants