feat: move errors helpers into shared pkg - #241
Conversation
db053d3 to
bcb8156
Compare
bcb8156 to
2652df8
Compare
There was a problem hiding this comment.
Pull request overview
Centralizes Snap RPC error normalization and tracking wrappers in snap-networks-utils for reuse across wallet Snaps.
Changes:
- Adds shared error helpers, types, exports, and tests.
- Migrates Stellar, Solana, and Tron error handling to shared utilities.
- Updates tracking behavior, manifests, coverage configuration, and changelog.
Reviewed changes
Copilot reviewed 35 out of 35 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
packages/tron-wallet-snap/src/utils/sensitiveErrors.ts |
Uses the shared RPC error guard. |
packages/tron-wallet-snap/src/utils/errors.ts |
Binds Tron tracking to the shared wrapper. |
packages/tron-wallet-snap/src/utils/errors.test.ts |
Updates wrapper integration tests. |
packages/tron-wallet-snap/src/clients/snap/SnapClient.ts |
Skips tracking user rejections. |
packages/tron-wallet-snap/src/clients/snap/SnapClient.test.ts |
Tests rejection suppression. |
packages/tron-wallet-snap/snap.manifest.json |
Updates the bundle checksum. |
packages/stellar-wallet-snap/src/utils/snap.ts |
Moves rejection filtering into tracking. |
packages/stellar-wallet-snap/src/utils/errors.ts |
Adopts the shared wrapper and types. |
packages/stellar-wallet-snap/src/utils/errors.test.ts |
Removes migrated utility tests. |
packages/stellar-wallet-snap/src/services/transaction/TransactionSynchronizeService.ts |
Uses the consolidated tracker. |
packages/stellar-wallet-snap/src/services/transaction/TransactionService.ts |
Uses the consolidated tracker. |
packages/stellar-wallet-snap/src/services/transaction/simulation/simulators.ts |
Updates tracking documentation. |
packages/stellar-wallet-snap/src/services/transaction-scan/TransactionScanService.ts |
Uses the consolidated tracker. |
packages/stellar-wallet-snap/src/services/sync/SynchronizeService.ts |
Uses the consolidated tracker. |
packages/stellar-wallet-snap/src/services/price/PriceService.ts |
Uses the consolidated tracker. |
packages/stellar-wallet-snap/src/services/on-chain-account/OnChainAccountSynchronizeService.ts |
Uses the consolidated tracker. |
packages/stellar-wallet-snap/src/services/on-chain-account/OnChainAccountSynchronizeService.test.ts |
Updates tracker spies. |
packages/stellar-wallet-snap/src/handlers/keyring/base.ts |
Uses the consolidated tracker. |
packages/stellar-wallet-snap/src/handlers/cronjob/trackTransaction.ts |
Uses the consolidated tracker. |
packages/stellar-wallet-snap/src/handlers/clientRequest/signAndSendTransaction.ts |
Uses the consolidated tracker. |
packages/stellar-wallet-snap/src/handlers/clientRequest/confirmSend.ts |
Uses the consolidated tracker. |
packages/stellar-wallet-snap/src/handlers/clientRequest/confirmSend.test.ts |
Updates tracker assertions. |
packages/stellar-wallet-snap/snap.manifest.json |
Updates the bundle checksum. |
packages/solana-wallet-snap/src/core/utils/errors.ts |
Adopts shared error utilities. |
packages/solana-wallet-snap/src/core/utils/errors.test.ts |
Updates tracking and wrapper tests. |
packages/solana-wallet-snap/snap.manifest.json |
Updates the bundle checksum. |
packages/snap-networks-utils/src/utils/logger/__mocks__/Logger.ts |
Adds a reusable logger mock. |
packages/snap-networks-utils/src/utils/errors/snapRpcError.ts |
Defines shared RPC error detection and types. |
packages/snap-networks-utils/src/utils/errors/index.ts |
Exports the error utilities. |
packages/snap-networks-utils/src/utils/errors/errors.ts |
Implements normalization and wrapper creation. |
packages/snap-networks-utils/src/utils/errors/errors.test.ts |
Tests shared error behavior. |
packages/snap-networks-utils/src/index.ts |
Publishes utilities from the package root. |
packages/snap-networks-utils/jest.config.js |
Excludes mocks from coverage. |
packages/snap-networks-utils/CHANGELOG.md |
Documents the new public exports. |
eslint-suppressions.json |
Removes obsolete suppressions. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
b449e00 to
fc77f9f
Compare
| }); | ||
| return keyringRequestResult; | ||
| }, this.#logger)) ?? null; | ||
| }, this.#logger.error.bind(this.#logger))) ?? null; |
There was a problem hiding this comment.
bind with the same object seem duplicate ?
There was a problem hiding this comment.
not really, this to bind the correct this, since we put there logger.error not the logger class.
There was a problem hiding this comment.
i see, we are forcing "this" of the error method from this.#logger, using this.#logger
| try { | ||
| return await fn(); | ||
| } catch (unknownError) { | ||
| await trackError(unknownError); |
There was a problem hiding this comment.
it may have duplicate track error
when snap it self already track the error from deeper level?
There was a problem hiding this comment.
that is how it worked previously on snaps, nothing has changed here, but as I know we do not track errors which we propagate up, we track suppressed errors or unhandled in this root handler
There was a problem hiding this comment.
u are , i was overlooked
stanleyyconsensys
left a comment
There was a problem hiding this comment.
didnt test yet, but it looks good to me
Explanation
createWithCatchAndThrowSnapErrorfor handler-boundary error catching, logging, and Snap RPC normalizationnormalizeErrorfor converting caught values into Snap RPC errors, with optional custom normalizers viacreateWithCatchAndThrowSnapError'snormalizeErrorFnoptionisSnapRpcErrortype guard andSnapRpcErrorunion typeReferences
Checklist