Skip to content

chore(tron-wallet-snap): type caught error values - #619

Open
ulissesferreira wants to merge 1 commit into
mainfrom
chore/tron-lint-suppressions-error-shapes
Open

ulissesferreira wants to merge 1 commit into
mainfrom
chore/tron-lint-suppressions-error-shapes

Conversation

@ulissesferreira

Copy link
Copy Markdown
Contributor

Summary

Fourth slice of the Tron Snap's oxlint-suppressions.json debt, split by type of change. This one clears caught error values that were typed any — 13 entries, 607 → 594 for packages/tron-wallet-snap on main after #611 and #613. It does not touch any of #612's files (no-in-operator).

  • sanitizeSensitiveError (utils/sensitiveErrors.ts, 11 entries) — took error: any and read error?.message / error?.stack off it. It now takes unknown and reads exactly those two fields through a small readErrorField helper (isObject from @metamask/utils + a typeof guard), so message and stack are string instead of any. The return type stays Error because PrepareErrorForTrackingFn ((error: unknown) => Error) requires it, and the "no sensitive keywords" path still returns the value untouched — including non-Error throwables, which the existing unit test asserts (sanitizeSensitiveError(null) is null).
  • SnapAssetsAdapter (2 entries) — the rejected Promise.allSettled entry was destructured through a separate isInactiveAccount boolean, so reason was any. The block now re-checks status === 'rejected' (which is what narrows the settled result) and annotates the rejected reason and the .catch callback parameter as unknown. Behaviour is unchanged: the same error is rethrown as AssetFetchError, the same account-not-found case proceeds, and the boolean still drives the TRC20 fallback below.

Nothing about which errors are sanitized, tracked, or thrown changes — only the types the code reaches them through.

Verification

  • yarn oxlint packages/tron-wallet-snap — clean (suppressions pruned)
  • yarn workspace @metamask/tron-wallet-snap exec tsc --project tsconfig.json --noEmit — clean
  • yarn workspace @metamask/tron-wallet-snap run test — 63 files / 1052 tests pass
  • oxfmt --check packages/tron-wallet-snap oxlint-suppressions.json — clean

Related PRs

#611 (test-related rules) and #613 (redundant type assertions) are merged. #612 (no-in-operator) is still open and untouched here; #618 (JSON.parse results and batch arrays) is the previous slice of the same cleanup and touches a disjoint file set.

`sanitizeSensitiveError` took `error: any` and read `error?.message` /
`error?.stack` off it, and `SnapAssetsAdapter` destructured the `any` reason of a
rejected `Promise.allSettled` entry — both made the error handling opaque to the
type checker.

- `sanitizeSensitiveError` now takes `unknown` and reads the two fields it
  inspects through a small `readErrorField` helper (`isObject` + `typeof`
  guard), so `message` / `stack` are `string` instead of `any`. The signature
  still returns `Error` because `PrepareErrorForTrackingFn` requires it, and
  non-sensitive values are still returned untouched (a `null` throw stays
  `null`, as the existing test asserts).
- `SnapAssetsAdapter` re-checks `status === 'rejected'` instead of reusing the
  `isInactiveAccount` boolean, which is what narrows the settled result, and
  annotates the rejected reason and the `.catch` callback parameter as
  `unknown`.

Clears 13 suppression entries (2 `no-unsafe-assignment` in `SnapAssetsAdapter`,
plus the whole `sensitiveErrors` block: 2 assignment, 4 call, 4 member-access,
1 return) — 607 → 594 for `packages/tron-wallet-snap`.

Verification:
- `yarn oxlint packages/tron-wallet-snap` clean (suppressions pruned)
- `tsc --project tsconfig.json --noEmit` clean
- `yarn workspace @metamask/tron-wallet-snap run test` — 63 files / 1052 tests
- `oxfmt --check` clean
@sonarqubecloud

Copy link
Copy Markdown

This branch was previously deployed

1 inactive deployment
default-branch — 9fe9ccf3 Deployed Nov 17, 2026 by ulissesferreira via Determine whether this PR is a release PR #2378
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.

1 participant