feat(wasm-utxo): expose structured error codes derived from Rust enum variant names#287
Merged
Merged
Conversation
77f68da to
9d9fd3a
Compare
Add a `WasmErrorCode` trait and `impl_wasm_error_code!` macro that derive
stable dotted error codes (e.g. `ParseTransactionError.Input/ParseInputError.WalletValidation`)
from Rust enum variant names via `strum::IntoStaticStr`.
The `From<WasmUtxoError> for JsValue` bridge attaches two properties to every
thrown `Error` via `Reflect::set`:
- `code`: a stable string code for dispatching on error type
- `Symbol.for('@bitgo/wasm-utxo/error')`: a brand marker so `isWasmUtxoError`
can distinguish WASM errors from unrelated errors that happen to have a `code`
string (e.g. Node.js ENOENT).
New variant names are exposed automatically — zero JS-side boilerplate per
error type. Existing `WasmUtxoError::new()` call sites fall back to the
`WasmUtxoError.StringError` code unchanged.
The TS surface adds an `isWasmUtxoError` type guard and `WasmUtxoError`
interface exported from the package root.
Refs: T1-3475
9d9fd3a to
3af1254
Compare
lcovar
approved these changes
May 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
WasmErrorCodetrait andimpl_wasm_error_code!macro that derive stable dotted error codes (e.g.ParseTransactionError.Input/ParseInputError.WalletValidation) from Rust enum variant names viastrum::IntoStaticStr— zero per-variant boilerplateFrom<WasmUtxoError> for JsValuebridge attaches acodestring property to every thrownErrorviaReflect::set; new Rust variants are automatically exposed with no JS changesWasmUtxoErrorinterface andisWasmUtxoErrortype guard to the TS package surface so callers can doisWasmUtxoError(err) && err.code.endsWith('ParseInputError.WalletValidation')instead of substring-matchingerr.messageDetails
ParseTransactionError.Input/ParseInputError.WalletValidationis the code for the Swan Bitcoin case (prod trace7ca965965a1eb6def3cae4097fd6d6a7, 2026-05-26) that prompted this ticket. Existing call sites usingWasmUtxoError::new()fall back to codeWasmUtxoError.StringErrorunchanged.Test plan
cargo test --lib— 447 tests pass (includes new unit tests for each error enum path)tsc --noEmit)@bitgo/wasm-utxoinindexerdb-microservice-utxoand replace the localisWasmUtxoErrorshim with the package importRefs: T1-3475