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

fix: Handle null return value from getMethodData to prevent destructuring error (#27457) #27462

Merged
merged 1 commit into from
Sep 27, 2024

Conversation

Gudahtt
Copy link
Member

@Gudahtt Gudahtt commented Sep 27, 2024

Description

The original code assumes that getMethodData will always return an object with a name property. However, in certain instances, getMethodData can return null. When this happens, destructuring the name property from null causes a runtime error.

To address this issue, the code has been updated to use optional chaining. This ensures that if getMethodData returns null, the destructuring will not occur, and contractMethodName will be set to undefined instead of causing an error.

Open in GitHub Codespaces

Related issues

Fixes: #27436

Manual testing steps

  1. Go to this page...

Screenshots/Recordings

Before

After

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.

#27457)

…ring error


<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->

The original code assumes that getMethodData will always return an
object with a name property. However, in certain instances,
getMethodData can return null. When this happens, destructuring the name
property from null causes a runtime error.

To address this issue, the code has been updated to use optional
chaining. This ensures that if getMethodData returns null, the
destructuring will not occur, and contractMethodName will be set to
undefined instead of causing an error.

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

## **Related issues**

Fixes: #27436

## **Manual testing steps**

1. Go to this page...
2.
3.

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] 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.
Copy link

sentry-io bot commented Sep 27, 2024

🔍 Existing Issues For Review

Your pull request is modifying functions with the following pre-existing issues:

📄 File: app/scripts/lib/transaction/metrics.ts

Function Unhandled Issue
buildEventFragmentProperties Error: KeyringController - No keyring found. Error info: There are no keyrings ...
Event Count: 1.1k Affected Users: 0
buildEventFragmentProperties TypeError: Cannot destructure property 'name' of '(intermediate value)' as it is null. ...
Event Count: 4 Affected Users: 0
buildEventFragmentProperties Error: KeyringController - No keyring found. Error info: There are no keyrings MetamaskController.getAccountType(app/s...
Event Count: 3 Affected Users: 0

Did you find this useful? React with a 👍 or 👎

Copy link
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@Gudahtt Gudahtt marked this pull request as ready for review September 27, 2024 18:42
@Gudahtt Gudahtt requested a review from a team as a code owner September 27, 2024 18:42
@Gudahtt Gudahtt added team-extension-platform team-confirmations Push issues to confirmations team labels Sep 27, 2024
@metamaskbot
Copy link
Collaborator

Builds ready [f9f22a9]
Page Load Metrics (1857 ± 116 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint25322301590594285
domContentLoaded139221841823237114
load139522331857241116
domInteractive146336126

Copy link

codecov bot commented Sep 27, 2024

Codecov Report

Attention: Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.

Project coverage is 70.15%. Comparing base (5f93766) to head (f9f22a9).

Files with missing lines Patch % Lines
app/scripts/lib/transaction/metrics.ts 0.00% 2 Missing ⚠️
Additional details and impacted files
@@               Coverage Diff                @@
##           Version-v12.3.1   #27462   +/-   ##
================================================
  Coverage            70.15%   70.15%           
================================================
  Files                 1431     1431           
  Lines                50436    50436           
  Branches             13994    13994           
================================================
  Hits                 35380    35380           
  Misses               15056    15056           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Gudahtt Gudahtt merged commit 31d1f14 into Version-v12.3.1 Sep 27, 2024
77 of 78 checks passed
@Gudahtt Gudahtt deleted the cherry-pick/get-method-data-null-return branch September 27, 2024 19:44
@github-actions github-actions bot locked and limited conversation to collaborators Sep 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
team-confirmations Push issues to confirmations team team-extension-platform
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants