Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: propagate data.cause as cause in JsonRpcError constructor #140

Merged
merged 5 commits into from
May 31, 2024

Conversation

legobeat
Copy link
Contributor

@legobeat legobeat commented May 12, 2024

This maps the tc39 error cause field on JsonRpcError instances to data.cause, if it exists and is an object. No further validation is performed.

This is done because adding es2022 or dom to tsconfig lib are not being considered at this point.

Related

Alternative

@legobeat legobeat marked this pull request as ready for review May 29, 2024 02:00
@legobeat legobeat requested a review from a team as a code owner May 29, 2024 02:00
tsconfig.json Outdated Show resolved Hide resolved
- break out util function dataHasCause with test
- comment clarity
- use native causes when available

note: jest coverage depends on runtime
@legobeat
Copy link
Contributor Author

legobeat commented May 31, 2024

Validated locally that tests also pass on Node.js v14, which definitely doesn't have support for causes. We also see the expected increase in jest coverage, there.

@legobeat legobeat requested a review from a team May 31, 2024 01:44
@legobeat
Copy link
Contributor Author

legobeat commented May 31, 2024

Updated with some improvements lifted over from #141 :

  • Try to set cause natively via superclass constructor; fall back to setting manually
    • Use safer methods Object.prototype.hasOwnProperty.call and Object.assign in fallback
  • Comment clarity after feedback
  • Minor type refactor for consistency

This branch has been published for evaluation as @metamask/[email protected]
Preview in extension

functions: 94.44,
lines: 92.85,
statements: 92.85,
branches: 91.89,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

legobeat added a commit to legobeat/metamask-extension that referenced this pull request May 31, 2024
published from 08108c535cf5ee25603715cbfae0cd9aa3f2dea6

MetaMask/rpc-errors#140
legobeat added a commit to legobeat/metamask-extension that referenced this pull request May 31, 2024
published from 08108c535cf5ee25603715cbfae0cd9aa3f2dea6

MetaMask/rpc-errors#140
src/classes.ts Outdated Show resolved Hide resolved
Copy link
Member

@rekmarks rekmarks left a comment

Choose a reason for hiding this comment

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

LGTM!

@legobeat legobeat merged commit 1b44940 into MetaMask:main May 31, 2024
18 checks passed
@legobeat
Copy link
Contributor Author

legobeat commented May 31, 2024

If any reviewers are still looking at this: Pending review in #144 so follow-ups are still NBD, if you see any room for improvement.

legobeat added a commit to legobeat/metamask-extension that referenced this pull request May 31, 2024
published from 08108c535cf5ee25603715cbfae0cd9aa3f2dea6

MetaMask/rpc-errors#140
legobeat added a commit to legobeat/metamask-extension that referenced this pull request May 31, 2024
published from 08108c535cf5ee25603715cbfae0cd9aa3f2dea6

MetaMask/rpc-errors#140
legobeat added a commit to legobeat/metamask-extension that referenced this pull request May 31, 2024
published from 08108c535cf5ee25603715cbfae0cd9aa3f2dea6

MetaMask/rpc-errors#140
legobeat added a commit to legobeat/metamask-extension that referenced this pull request May 31, 2024
published from 08108c535cf5ee25603715cbfae0cd9aa3f2dea6

MetaMask/rpc-errors#140
legobeat added a commit to legobeat/metamask-extension that referenced this pull request May 31, 2024
published from 08108c535cf5ee25603715cbfae0cd9aa3f2dea6

MetaMask/rpc-errors#140
legobeat added a commit to legobeat/metamask-extension that referenced this pull request May 31, 2024
published from 08108c535cf5ee25603715cbfae0cd9aa3f2dea6

MetaMask/rpc-errors#140
legobeat added a commit to legobeat/metamask-extension that referenced this pull request May 31, 2024
published from 08108c535cf5ee25603715cbfae0cd9aa3f2dea6

MetaMask/rpc-errors#140
legobeat added a commit to legobeat/metamask-extension that referenced this pull request May 31, 2024
published from 08108c535cf5ee25603715cbfae0cd9aa3f2dea6

MetaMask/rpc-errors#140
legobeat added a commit to legobeat/metamask-extension that referenced this pull request May 31, 2024
published from 08108c535cf5ee25603715cbfae0cd9aa3f2dea6

MetaMask/rpc-errors#140
legobeat added a commit to legobeat/metamask-extension that referenced this pull request May 31, 2024
published from 08108c535cf5ee25603715cbfae0cd9aa3f2dea6

MetaMask/rpc-errors#140
legobeat added a commit to legobeat/metamask-extension that referenced this pull request May 31, 2024
published from 08108c535cf5ee25603715cbfae0cd9aa3f2dea6

MetaMask/rpc-errors#140
legobeat added a commit to legobeat/metamask-extension that referenced this pull request Jun 1, 2024
published from 08108c535cf5ee25603715cbfae0cd9aa3f2dea6

MetaMask/rpc-errors#140
legobeat added a commit to legobeat/metamask-extension that referenced this pull request Jun 1, 2024
published from 08108c535cf5ee25603715cbfae0cd9aa3f2dea6

MetaMask/rpc-errors#140
legobeat added a commit to legobeat/metamask-extension that referenced this pull request Jun 5, 2024
published from 08108c535cf5ee25603715cbfae0cd9aa3f2dea6

MetaMask/rpc-errors#140
legobeat added a commit to legobeat/metamask-extension that referenced this pull request Jun 5, 2024
published from 08108c535cf5ee25603715cbfae0cd9aa3f2dea6

MetaMask/rpc-errors#140
Gudahtt pushed a commit to MetaMask/metamask-extension that referenced this pull request Oct 16, 2024
…edition) (#24496)

## **Description**

- Upgrade from obsolete `eth-rpc-errors` to `@metamask/rpc-errors`
  - This introduce handling of error causes 


See [here](MetaMask/rpc-errors#140) for some
context.

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/24496?quickstart=1)

## **Related issues**

- #22871

#### Blocked by
- [x] MetaMask/rpc-errors#158
- [x] MetaMask/rpc-errors#144
  - [x] MetaMask/rpc-errors#140

#### Blocking
- #22875

## **Manual testing steps**

## **Screenshots/Recordings**

### **Before**

### **After**

## **Pre-merge author checklist**

- [x] I’ve followed [MetaMask Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.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/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **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.
Gudahtt pushed a commit to MetaMask/metamask-extension that referenced this pull request Oct 21, 2024
…edition) (#24496)

- Upgrade from obsolete `eth-rpc-errors` to `@metamask/rpc-errors`
  - This introduce handling of error causes

See [here](MetaMask/rpc-errors#140) for some
context.

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/24496?quickstart=1)

- #22871

- [x] MetaMask/rpc-errors#158
- [x] MetaMask/rpc-errors#144
  - [x] MetaMask/rpc-errors#140

- #22875

- [x] I’ve followed [MetaMask Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.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/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

- [ ] 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.
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.

2 participants