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

Added MIP for fix error handling in API Responses #36

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

shanejonas
Copy link
Contributor

@shanejonas shanejonas commented Mar 4, 2024

This proposal aims to refine MetaMask's API error handling by eliminating the practice of stringifying or wrapping errors. The current method obscures underlying issues, complicating debugging and resolution for developers.

adonesky1
adonesky1 previously approved these changes Mar 4, 2024
Copy link
Collaborator

@adonesky1 adonesky1 left a comment

Choose a reason for hiding this comment

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

Looks good and straightforward in general. Though I think it would be good to get more examples in here

MIPs/mip-x .md Outdated Show resolved Hide resolved
MIPs/mip-x .md Outdated Show resolved Hide resolved
MIPs/mip-x .md Outdated Show resolved Hide resolved
MIPs/mip-x .md Outdated Show resolved Hide resolved
@adonesky1
Copy link
Collaborator

Would also be good to add some timeline guidance for when we might be rolling this out

MIPs/mip-x .md Outdated Show resolved Hide resolved
@shanejonas
Copy link
Contributor Author

@adonesky1 not sure what we should put for the timeline. any ideas?

@jiexi
Copy link
Collaborator

jiexi commented Mar 4, 2024

6 months after MIP finalized? We should also mention that we will provide several example wrapped stringified errors and what they will look like after the changes.

@adonesky1
Copy link
Collaborator

not sure what we should put for the timeline. any ideas?

6 months after MIP finalized?

6 months seems like a lot to me... Maybe 3 months after finalized? Maybe we should check with @Gudahtt about how long we've waited in the past? We should probably have some protocol going forward.

Issue https://github.com/MetaMask/metamask-extension/issues/19697, https://github.com/MetaMask/metamask-extension/issues/15250 and https://github.com/MetaMask/metamask-extension/pull/15205#issuecomment-1199953855 highlighted difficulties faced by developers due to the API's error handling mechanism, where some errors are wrapped and stringified. This change proposes to break some existing error cases to facilitate clearer understanding and quicker resolution of issues.

#### Specification
- **Current Behaviour:** Errors returned by the API are wrapped and stringified, leading to terribly formatted error messages in some cases.
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I had always thought of this as a bug, rather than a part of how the API works. But it's a fair point that we would expect dapps to expect these responses.

Do we know if we return these mangled stringified errors for all errors? Or just certain classes of them? I thought we returned proper Ethereum JSON-RPC errors at least some of the time.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Would be good to drill in on what specific methods/scenarios we see these poorly formatted errors.

MIPs/mip-x .md Outdated Show resolved Hide resolved
MIPs/mip-x .md Outdated Show resolved Hide resolved
MIPs/mip-x .md Outdated Show resolved Hide resolved
shanejonas and others added 3 commits March 7, 2024 07:28
Co-authored-by: Alex Donesky <[email protected]>
@shanejonas
Copy link
Contributor Author

This MIP will be closed as it came to our attention when trying to reproduce these errors that the wrapping issue has been resolved. Below is a Postmortem.

The Journey through Error Wrapping in MetaMask

Background
We encountered an issue reproducing an error while writing an MIP to fix error wrapping here. It turned out to be related to error handling in the new merged transaction controller. This postmortem aims to shed light on the issue the lessons learned from this experience.

The Issue
The crux of the problem was discovered in the transition from using ethjs-query to eth-query for handling transactions within MetaMask. A crucial difference between these libraries is their approach to error handling, specifically, how they wrap errors. The original library, ethjs-query, employed a method of wrapping errors made debugging more difficult. However, this behaviour was changed when merging transaction controllers which also switched to eth-query, a library that does not implement error wrapping in the same way.

Reference to the old transaction controller can be found here, and the new transaction controller utilizing eth-query is documented here.

Discovery and Resolution
The issue was identified when it was noted that the old implementation using eth-query led to wrapped errors, complicating the debugging process and potentially impacting user experience. This change, although seemingly minor, had significant implications for error handling within MetaMasks API.

Further investigation revealed that ethjs-query itself underwent a change that removed the error wrapping functionality in a separate change. This change is detailed in a commit found here, adding another layer of complexity to the situation.

Challenges and Insights
One of the most alarming aspects of this issue was the realization that there were no tests or mechanisms in place to catch such a critical change in error handling behaviour. This oversight highlighted a significant gap in the development and quality assurance processes within the project.

Lessons Learned
Several key lessons emerged from this experience:

  1. The Importance of Error Handling: Proper error wrapping and handling are crucial for maintainability and ease of debugging, especially in complex projects like MetaMask.
  2. Testing and Coverage: This incident underscored the need for comprehensive testing, including tests that specifically address error handling behaviours, to prevent similar issues in the future.
  3. Library Dependencies: Changes in external library dependencies can have unforeseen impacts. It's essential to thoroughly review and test any library updates or replacements.
  4. Communication and Documentation: The confusion surrounding the change in error handling behaviour highlights the importance of clear communication and documentation, both within the team and with the broader user and developer community.

Moving Forward
In response to this issue, we are taking steps to enhance its testing and quality assurance processes, with a focus on preventing similar problems in the future. This includes implementing more comprehensive tests covering error handling and error messages.

github-merge-queue bot pushed a commit to MetaMask/metamask-extension that referenced this pull request Oct 18, 2024
#22875)

## **Description**

## **Related issues**

- #27784
- MetaMask/eth-json-rpc-middleware#335
- #27917
- #18510
- #15250
- MetaMask/metamask-improvement-proposals#36

### Blocked by
- [x] #24496

### Follow-up to
- #24496

## **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 clearly explained what problem this PR is solving and how it
is solved.
- [x] I've linked related issues
- [x] I've included manual testing steps
- [x] I've included screenshots/recordings if applicable
- [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.
- [x] I’ve properly set the pull request status:
  - [x] In case it's not yet "ready for review", I've set it to "draft".
- [x] In case it's "ready for review", I've changed it from "draft" to
"non-draft".

## **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.
vinistevam pushed a commit to MetaMask/metamask-extension that referenced this pull request Oct 20, 2024
#22875)

## **Description**

## **Related issues**

- #27784
- MetaMask/eth-json-rpc-middleware#335
- #27917
- #18510
- #15250
- MetaMask/metamask-improvement-proposals#36

### Blocked by
- [x] #24496

### Follow-up to
- #24496

## **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 clearly explained what problem this PR is solving and how it
is solved.
- [x] I've linked related issues
- [x] I've included manual testing steps
- [x] I've included screenshots/recordings if applicable
- [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.
- [x] I’ve properly set the pull request status:
  - [x] In case it's not yet "ready for review", I've set it to "draft".
- [x] In case it's "ready for review", I've changed it from "draft" to
"non-draft".

## **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
#22875)

- #27784
- MetaMask/eth-json-rpc-middleware#335
- #27917
- #18510
- #15250
- MetaMask/metamask-improvement-proposals#36

- [x] #24496

- #24496

- [x] I’ve followed [MetaMask Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've clearly explained what problem this PR is solving and how it
is solved.
- [x] I've linked related issues
- [x] I've included manual testing steps
- [x] I've included screenshots/recordings if applicable
- [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.
- [x] I’ve properly set the pull request status:
  - [x] In case it's not yet "ready for review", I've set it to "draft".
- [x] In case it's "ready for review", I've changed it from "draft" to
"non-draft".

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

5 participants