Skip to content

feat(wasm-utxo): expose structured error codes derived from Rust enum variant names#287

Merged
OttoAllmendinger merged 1 commit into
masterfrom
otto/t1-3475-wasm-utxo-error-codes
May 28, 2026
Merged

feat(wasm-utxo): expose structured error codes derived from Rust enum variant names#287
OttoAllmendinger merged 1 commit into
masterfrom
otto/t1-3475-wasm-utxo-error-codes

Conversation

@OttoAllmendinger
Copy link
Copy Markdown
Contributor

Summary

  • Adds 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 — zero per-variant boilerplate
  • The single From<WasmUtxoError> for JsValue bridge attaches a code string property to every thrown Error via Reflect::set; new Rust variants are automatically exposed with no JS changes
  • Adds WasmUtxoError interface and isWasmUtxoError type guard to the TS package surface so callers can do isWasmUtxoError(err) && err.code.endsWith('ParseInputError.WalletValidation') instead of substring-matching err.message

Details

ParseTransactionError.Input/ParseInputError.WalletValidation is the code for the Swan Bitcoin case (prod trace 7ca965965a1eb6def3cae4097fd6d6a7, 2026-05-26) that prompted this ticket. Existing call sites using WasmUtxoError::new() fall back to code WasmUtxoError.StringError unchanged.

Test plan

  • cargo test --lib — 447 tests pass (includes new unit tests for each error enum path)
  • TypeScript compiles cleanly (tsc --noEmit)
  • After release, bump @bitgo/wasm-utxo in indexerdb-microservice-utxo and replace the local isWasmUtxoError shim with the package import

Refs: T1-3475

@OttoAllmendinger OttoAllmendinger requested a review from a team as a code owner May 28, 2026 09:22
@linear-code
Copy link
Copy Markdown

linear-code Bot commented May 28, 2026

T1-3475

@OttoAllmendinger OttoAllmendinger force-pushed the otto/t1-3475-wasm-utxo-error-codes branch 2 times, most recently from 77f68da to 9d9fd3a Compare May 28, 2026 13:59
@OttoAllmendinger OttoAllmendinger marked this pull request as draft May 28, 2026 14:15
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
@OttoAllmendinger OttoAllmendinger force-pushed the otto/t1-3475-wasm-utxo-error-codes branch from 9d9fd3a to 3af1254 Compare May 28, 2026 14:24
@OttoAllmendinger OttoAllmendinger marked this pull request as ready for review May 28, 2026 14:49
@OttoAllmendinger OttoAllmendinger merged commit 28231ae into master May 28, 2026
17 checks passed
@OttoAllmendinger OttoAllmendinger deleted the otto/t1-3475-wasm-utxo-error-codes branch May 28, 2026 19:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants