fix: include BDK cause in PSBT build error message#594
Merged
cloudonshore merged 6 commits intomainfrom Mar 31, 2026
Merged
Conversation
The "Failed to build PSBT from template" error loses its cause when crossing the snap JSON-RPC boundary. This makes it impossible to diagnose why BDK's transaction builder fails (e.g. InsufficientFunds, OutputBelowDustLimit, NoUtxosSelected). - Append the BDK cause message to the ValidationError message string so it survives serialization through HandlerMiddleware and appears in Sentry/Mixpanel - Wrap BdkTxBuilderAdapter.finish() to convert CodifiedError (WASM plain object) into a real Error instance so instanceof checks work
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Battambang
approved these changes
Mar 31, 2026
This was referenced Apr 1, 2026
github-merge-queue bot
pushed a commit
to MetaMask/metamask-mobile
that referenced
this pull request
Apr 1, 2026
## **Description** Bumps `@metamask/bitcoin-wallet-snap` from `^1.10.0` to `^1.10.1`. Release PR: MetaMask/snap-bitcoin-wallet#595 Notable change: - [fix: include BDK cause in PSBT build error message](MetaMask/snap-bitcoin-wallet#594) — surfaces the underlying BDK root cause (e.g. `InsufficientFunds`, `OutputBelowDustLimit`) in PSBT build error messages so they appear in Sentry/Mixpanel instead of being lost at the RPC boundary. ## **Changelog** CHANGELOG entry: Fixed Bitcoin PSBT build errors now include the underlying cause for better diagnostics ## **Related issues** Fixes: ## **Manual testing steps** 1. Create a Bitcoin account 2. Trigger a PSBT build failure (e.g. insufficient funds swap) 3. Verify the error message in Sentry/Mixpanel includes the BDK cause ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I've included tests if applicable - [x] I've documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I've applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Low risk dependency-only bump with no application code changes; any impact is limited to behavior changes inside the updated snap package. > > **Overview** > **Bumps the Bitcoin snap dependency** by updating `@metamask/bitcoin-wallet-snap` from `^1.10.0` to `^1.10.1` in `package.json`. > > Updates `yarn.lock` to resolve and checksum the new `1.10.1` release. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit d858417. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
github-merge-queue bot
pushed a commit
to MetaMask/metamask-extension
that referenced
this pull request
Apr 1, 2026
## **Description** Bumps `@metamask/bitcoin-wallet-snap` from `^1.10.0` to `^1.10.1`. Release PR: MetaMask/snap-bitcoin-wallet#595 Notable change: - [fix: include BDK cause in PSBT build error message](MetaMask/snap-bitcoin-wallet#594) — surfaces the underlying BDK root cause (e.g. `InsufficientFunds`, `OutputBelowDustLimit`) in PSBT build error messages so they appear in Sentry/Mixpanel instead of being lost at the RPC boundary. ## **Changelog** CHANGELOG entry: Fixed Bitcoin PSBT build errors now include the underlying cause for better diagnostics ## **Related issues** Fixes: ## **Manual testing steps** 1. Create a Bitcoin account 2. Trigger a PSBT build failure (e.g. insufficient funds swap) 3. Verify the error message in Sentry/Mixpanel includes the BDK cause ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I've included tests if applicable - [x] I've documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I've applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Patch-level dependency bump for the Bitcoin snap; primary risk is behavior changes in Bitcoin PSBT build/error propagation affecting diagnostics or edge-case flows. > > **Overview** > Updates the extension’s bundled Bitcoin snap dependency by bumping `@metamask/bitcoin-wallet-snap` from `^1.10.0` to `^1.10.1`, with the corresponding `yarn.lock` resolution/checksum update. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 081af90. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
github-merge-queue bot
pushed a commit
to MetaMask/metamask-extension
that referenced
this pull request
Apr 1, 2026
## **Description** Bumps `@metamask/bitcoin-wallet-snap` from `^1.10.0` to `^1.10.1`. Release PR: MetaMask/snap-bitcoin-wallet#595 Notable change: - [fix: include BDK cause in PSBT build error message](MetaMask/snap-bitcoin-wallet#594) — surfaces the underlying BDK root cause (e.g. `InsufficientFunds`, `OutputBelowDustLimit`) in PSBT build error messages so they appear in Sentry/Mixpanel instead of being lost at the RPC boundary. ## **Changelog** CHANGELOG entry: Fixed Bitcoin PSBT build errors now include the underlying cause for better diagnostics ## **Related issues** Fixes: ## **Manual testing steps** 1. Create a Bitcoin account 2. Trigger a PSBT build failure (e.g. insufficient funds swap) 3. Verify the error message in Sentry/Mixpanel includes the BDK cause ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I've included tests if applicable - [x] I've documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I've applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Patch-level dependency bump for the Bitcoin snap; primary risk is behavior changes in Bitcoin PSBT build/error propagation affecting diagnostics or edge-case flows. > > **Overview** > Updates the extension’s bundled Bitcoin snap dependency by bumping `@metamask/bitcoin-wallet-snap` from `^1.10.0` to `^1.10.1`, with the corresponding `yarn.lock` resolution/checksum update. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 081af90. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
github-merge-queue bot
pushed a commit
to MetaMask/metamask-extension
that referenced
this pull request
Apr 1, 2026
## **Description** Bumps `@metamask/bitcoin-wallet-snap` from `^1.10.0` to `^1.10.1`. Release PR: MetaMask/snap-bitcoin-wallet#595 Notable change: - [fix: include BDK cause in PSBT build error message](MetaMask/snap-bitcoin-wallet#594) — surfaces the underlying BDK root cause (e.g. `InsufficientFunds`, `OutputBelowDustLimit`) in PSBT build error messages so they appear in Sentry/Mixpanel instead of being lost at the RPC boundary. ## **Changelog** CHANGELOG entry: Fixed Bitcoin PSBT build errors now include the underlying cause for better diagnostics ## **Related issues** Fixes: ## **Manual testing steps** 1. Create a Bitcoin account 2. Trigger a PSBT build failure (e.g. insufficient funds swap) 3. Verify the error message in Sentry/Mixpanel includes the BDK cause ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I've included tests if applicable - [x] I've documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I've applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Patch-level dependency bump for the Bitcoin snap; primary risk is behavior changes in Bitcoin PSBT build/error propagation affecting diagnostics or edge-case flows. > > **Overview** > Updates the extension’s bundled Bitcoin snap dependency by bumping `@metamask/bitcoin-wallet-snap` from `^1.10.0` to `^1.10.1`, with the corresponding `yarn.lock` resolution/checksum update. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 081af90. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
github-merge-queue bot
pushed a commit
to MetaMask/metamask-extension
that referenced
this pull request
Apr 1, 2026
## **Description** Bumps `@metamask/bitcoin-wallet-snap` from `^1.10.0` to `^1.10.1`. Release PR: MetaMask/snap-bitcoin-wallet#595 Notable change: - [fix: include BDK cause in PSBT build error message](MetaMask/snap-bitcoin-wallet#594) — surfaces the underlying BDK root cause (e.g. `InsufficientFunds`, `OutputBelowDustLimit`) in PSBT build error messages so they appear in Sentry/Mixpanel instead of being lost at the RPC boundary. ## **Changelog** CHANGELOG entry: Fixed Bitcoin PSBT build errors now include the underlying cause for better diagnostics ## **Related issues** Fixes: ## **Manual testing steps** 1. Create a Bitcoin account 2. Trigger a PSBT build failure (e.g. insufficient funds swap) 3. Verify the error message in Sentry/Mixpanel includes the BDK cause ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I've included tests if applicable - [x] I've documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I've applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Patch-level dependency bump for the Bitcoin snap; primary risk is behavior changes in Bitcoin PSBT build/error propagation affecting diagnostics or edge-case flows. > > **Overview** > Updates the extension’s bundled Bitcoin snap dependency by bumping `@metamask/bitcoin-wallet-snap` from `^1.10.0` to `^1.10.1`, with the corresponding `yarn.lock` resolution/checksum update. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 081af90. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
github-merge-queue bot
pushed a commit
to MetaMask/metamask-extension
that referenced
this pull request
Apr 2, 2026
## **Description** Bumps `@metamask/bitcoin-wallet-snap` from `^1.10.0` to `^1.10.1`. Release PR: MetaMask/snap-bitcoin-wallet#595 Notable change: - [fix: include BDK cause in PSBT build error message](MetaMask/snap-bitcoin-wallet#594) — surfaces the underlying BDK root cause (e.g. `InsufficientFunds`, `OutputBelowDustLimit`) in PSBT build error messages so they appear in Sentry/Mixpanel instead of being lost at the RPC boundary. ## **Changelog** CHANGELOG entry: Fixed Bitcoin PSBT build errors now include the underlying cause for better diagnostics ## **Related issues** Fixes: ## **Manual testing steps** 1. Create a Bitcoin account 2. Trigger a PSBT build failure (e.g. insufficient funds swap) 3. Verify the error message in Sentry/Mixpanel includes the BDK cause ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I've included tests if applicable - [x] I've documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I've applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Patch-level dependency bump for the Bitcoin snap; primary risk is behavior changes in Bitcoin PSBT build/error propagation affecting diagnostics or edge-case flows. > > **Overview** > Updates the extension’s bundled Bitcoin snap dependency by bumping `@metamask/bitcoin-wallet-snap` from `^1.10.0` to `^1.10.1`, with the corresponding `yarn.lock` resolution/checksum update. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 081af90. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
github-merge-queue bot
pushed a commit
to MetaMask/metamask-extension
that referenced
this pull request
Apr 2, 2026
## **Description** Bumps `@metamask/bitcoin-wallet-snap` from `^1.10.0` to `^1.10.1`. Release PR: MetaMask/snap-bitcoin-wallet#595 Notable change: - [fix: include BDK cause in PSBT build error message](MetaMask/snap-bitcoin-wallet#594) — surfaces the underlying BDK root cause (e.g. `InsufficientFunds`, `OutputBelowDustLimit`) in PSBT build error messages so they appear in Sentry/Mixpanel instead of being lost at the RPC boundary. ## **Changelog** CHANGELOG entry: Fixed Bitcoin PSBT build errors now include the underlying cause for better diagnostics ## **Related issues** Fixes: ## **Manual testing steps** 1. Create a Bitcoin account 2. Trigger a PSBT build failure (e.g. insufficient funds swap) 3. Verify the error message in Sentry/Mixpanel includes the BDK cause ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I've included tests if applicable - [x] I've documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I've applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Patch-level dependency bump for the Bitcoin snap; primary risk is behavior changes in Bitcoin PSBT build/error propagation affecting diagnostics or edge-case flows. > > **Overview** > Updates the extension’s bundled Bitcoin snap dependency by bumping `@metamask/bitcoin-wallet-snap` from `^1.10.0` to `^1.10.1`, with the corresponding `yarn.lock` resolution/checksum update. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 081af90. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
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.

Problem
The "Failed to build PSBT from template" error is one of the top errors in Unified SwapBridge (~7.5% of failures). The root cause from BDK (e.g.
InsufficientFunds,OutputBelowDustLimit,NoUtxosSelected) is lost when crossing the snap JSON-RPC boundary because:HandlerMiddlewarere-throws asInvalidParamsErrorwhich doesn't accept acauseparameter (line 71)emitTrackingErrorcheckserror.cause instanceof Errorbut BDK WASM errors areCodifiedErrorplain objects, notErrorinstances (line 308)This makes it impossible to diagnose why the PSBT rebuild fails in Sentry or Mixpanel.
Solution
Append the BDK cause message to the
ValidationErrormessage string so it survives serialization through the RPC boundary and appears in Sentry/Mixpanel. Handles bothErrorinstances and BDK'sCodifiedErrorplain objects.After this change, errors will appear as:
instead of:
Test plan
Note
Low Risk
Low risk: changes are limited to error-message composition and accompanying unit tests, with no effect on PSBT construction logic. Main potential impact is on any consumers asserting exact error strings.
Overview
PSBT build failures now surface the underlying cause message. When
AccountUseCases.#fillPsbtfails tofinish()a transaction, the thrownValidationErrormessage is updated from a generic "Failed to build PSBT from template" to include the caught error’s.message(orunknown causewhen absent), ensuring the reason survives RPC serialization.Tests are updated/added to cover
Errorcauses, non-Errorobject causes, and missing-message causes, and the change is documented in the Unreleased changelog (with the snapmanifestshasumupdated for the new bundle).Written by Cursor Bugbot for commit a0413df. This will update automatically on new commits. Configure here.