Skip to content

Conversation

@mj-kiwi
Copy link
Contributor

@mj-kiwi mj-kiwi commented Jan 6, 2026

Description

This PR improves error observability for the gator snap by introducing Sentry-based error tracking via MetaMask.

A new ErrorTracker abstraction is added, which reports errors using the snap_trackError method so that runtime failures inside snaps can be surfaced in Sentry. Since snap_trackError currently only supports a basic error payload and does not expose Sentry-specific features such as tags, relevant snap metadata (e.g. snap name) is embedded into the error message itself.

On the Sentry side, alerts are configured to filter errors originating from gator-permissions-snap and permissions-kernel-snap, and forward those errors to the team via email notifications. This allows us to proactively monitor snap errors and respond more quickly to production issues.

Related issues

Fixes: N/A

Manual testing steps

  1. Trigger a known error path inside the gator snap (e.g. throw an error from a snap handler).
  2. Verify that ErrorTracker calls snap_trackError with the expected error payload.
  3. Confirm the error appears in Sentry with the snap metadata included in the error message.
  4. Verify that the Sentry alert is triggered and an email is sent to the team for gator-related errors.

Screenshots/Recordings

Before

After

Email as below

image

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Note

Adds centralized error tracking and integrates it into RPC flows for better observability.

  • Shared utils: New SnapErrorTracker with createErrorTracker/getErrorTracker, captureError, and captureResponseError in @metamask/7715-permissions-shared/utils/errorTracking; re-exported via ./utils and added export ./error-tracking. Added @metamask/snaps-sdk dependency.
  • Gator snap: Initializes tracker (snapName: 'gator-permissions-snap') and wraps onRpcRequest in try/catch to report via errorTracker.captureError. Added optional RPC wrappers in rpc/rpcErrorHandler.ts for per-method tracking.
  • Permissions kernel snap: Initializes tracker (snapName: 'permissions-kernel-snap') and reports errors in onRpcRequest. Added rpc/rpcErrorHandler.ts with wrapper utilities.
  • Misc: Updated yarn.lock and package exports.

Written by Cursor Bugbot for commit 244595a. This will update automatically on new commits. Configure here.

@mj-kiwi mj-kiwi marked this pull request as ready for review January 15, 2026 21:20
@mj-kiwi mj-kiwi requested a review from a team as a code owner January 15, 2026 21:20
@mj-kiwi mj-kiwi changed the title [DRAFT] feat: integrate error tracking service with RPC handlers feat: integrate error tracking service with RPC handlers Jan 15, 2026
// By default, track all errors that are Error instances or have error-like properties
return (
error instanceof Error ||
(typeof error === 'object' && (error?.message ?? error?.error))
Copy link

Choose a reason for hiding this comment

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

Nullish coalescing causes errors to go untracked

Medium Severity

The shouldTrackError function uses ?? (nullish coalescing) instead of || (logical OR) in the expression error?.message ?? error?.error. This means error objects with an empty string message property but a truthy error property won't be tracked, even though they have error-like properties. The ?? operator only checks for null/undefined, so { message: '', error: 'something' } evaluates to '' (falsy) and won't be tracked.

Fix in Cursor Fix in Web

const errorInfo: ErrorTrackingInfo = {
snapName: this.#snapName,
method,
errorMessage: `Response error: ${JSON.stringify(response)}`,
Copy link

Choose a reason for hiding this comment

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

Unprotected JSON.stringify can throw during error capture

Low Severity

JSON.stringify() calls in captureResponseError (line 180) and #extractErrorInfo (line 82) occur outside the try-catch block in #trackErrorViaSnap. If the input contains circular references, BigInt values, or other non-serializable data, these calls throw unhandled exceptions. This defeats the intent to "safely handle error tracking without throwing additional errors" as stated in the code comments.

Additional Locations (1)

Fix in Cursor Fix in Web

Copy link
Contributor

@MoMannn MoMannn left a comment

Choose a reason for hiding this comment

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

Also some cursor bug bot things to address

Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need this? We are not using it anywhere? Also this code is duplicated in permissions-kernel-snap and not used there either?

"./constants": "./src/constants/index.ts",
"./testing": "./src/testing/index.ts"
"./testing": "./src/testing/index.ts",
"./error-tracking": "./src/utils/errorTracking.ts"
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this exported here? its already exported in index.ts?

@mj-kiwi mj-kiwi marked this pull request as draft January 19, 2026 19:57
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.

3 participants