Skip to content

chore: track all errors in handle middleware WPN-1451#632

Open
taran-a wants to merge 6 commits into
mainfrom
chore/trackError-in-HandleMiddleware
Open

chore: track all errors in handle middleware WPN-1451#632
taran-a wants to merge 6 commits into
mainfrom
chore/trackError-in-HandleMiddleware

Conversation

@taran-a

@taran-a taran-a commented Jun 24, 2026

Copy link
Copy Markdown

Explanation

Improves Snap observability and trace handling by centralizing error/event tracking resilience in SnapClientAdapter, broadening HandlerMiddleware to track unexpected errors, and skipping tracking for user-canceled confirmations. It also simplifies callers by removing runSnapActionSafely, updates trace semantics so endTrace only runs when startTrace succeeds, and adds/refreshes tests covering the new tracking and tracing behavior.

References

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

Note

Medium Risk
Touches cross-cutting error/telemetry paths and cron partial-sync behavior; failures in tracking are swallowed (by design) which could hide telemetry outages but should not block user flows.

Overview
Improves Bitcoin Snap observability by making telemetry non-fatal and tracking more consistent across handlers and use cases.

SnapClientAdapter now takes a Logger, wraps snap_trackEvent, snap_trackError, snap_startTrace, and snap_endTrace in try/catch (log on failure, never throw), sends errors via getJsonError, and changes startTrace to return boolean so callers only call endTrace when start succeeded.

HandlerMiddleware tracks errors before translation/wrapping for any thrown error via new shouldTrackError (skips "User canceled the confirmation"). BaseError-only tracking in the middleware catch path is removed in favor of this broader path.

Call sites drop runSnapActionSafely and call tracking directly; emitTrackingError is wired into asset price/historical failures, partial cron sync failures, keyring address resolution failures, send-flow/confirmation graceful fallbacks, and related paths. User-input validation (RPC address/amount, some send-form fields) stays untracked by design.

SnapClient types update emitTrackingError to accept Error and document the new trace return type. Tests cover adapter resilience, middleware tracking rules, and updated trace behavior.

Reviewed by Cursor Bugbot for commit 3e84cde. Bugbot is set up for automated code reviews on this repo. Configure here.

@taran-a taran-a requested a review from a team as a code owner June 24, 2026 13:52

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 8406c25. Configure here.

Comment thread packages/snap/src/infra/SnapClientAdapter.test.ts Outdated
Battambang
Battambang previously approved these changes Jun 24, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/bitcoin-wallet-snap": "1.14.1-preview-fc27456"
}

* chore: track errors in AssetsUseCases

* chore: track errors in SendFlowUseCases

* chore: track errors in Assets, Cron, Keyring, and Rpc handlers

* chore: comment suppressed errors intent in mappings
@taran-a

taran-a commented Jun 26, 2026

Copy link
Copy Markdown
Author

@metamaskbot publish-preview

@github-actions

Copy link
Copy Markdown
Contributor

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/bitcoin-wallet-snap": "1.14.1-preview-3e84cde"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants