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(core/axios): handle un-writable error stack #6362

Merged

Conversation

alexandre-abrioux
Copy link
Contributor

@alexandre-abrioux alexandre-abrioux commented Apr 19, 2024

Issue

We've observed many reports of the following error on a production front-end after upgrading from 1.6.2 to 1.6.7. The latest version 1.6.8 is also impacted.

TypeError: Attempted to assign to read-only property.
  at Axios$1.request(../../node_modules/.pnpm/axios@1.6.8/node_modules/axios/lib/core/Axios.js:54:24)

We've also noticed another similar error, which is probably triggered by a different type of browser:

TypeError: setting getter-only property "stack"
  at Axios$1.request(../../node_modules/.pnpm/axios@1.6.8/node_modules/axios/lib/core/Axios.js:54:31)

Cause

Native network exceptions thrown by some browsers have an un-writable stack property. With current code, it results in the above error triggered from this line of code.

I suspect this bug was introduced by #6203.

Fix

This PR adds a failing test (first commit) and fixes the issue (second commit).

Please let me know if you have any recommendations 🙂

@DigitalBrainJS
Copy link
Collaborator

Not sure, but there may be some cases when the field is not writable, but has a falsy value, or an error is thrown inside the setter. The user (or some third-party code on a custom platform) can override the descriptor in a custom error class with a custom setter that throws an error, but we will not be able to determine that it is unwritable by checking writable prop. It might be worth just wrapping the condition block with assignments with another try-catch block to swallow all possible errors. In addition, in this case, there will be less code.

@alexandre-abrioux
Copy link
Contributor Author

@DigitalBrainJS Thanks for the suggestion! I've updated the code with a try-catch instead 🙂 The test is green ✅

@alexandre-abrioux
Copy link
Contributor Author

@DigitalBrainJS Thanks again for your review! I updated the tests to handle all the cases we talked about, and wrapping the entire if-else block with the try-catch does the trick 👍

@DigitalBrainJS DigitalBrainJS merged commit 81e0455 into axios:v1.x May 7, 2024
9 checks passed
@github-actions github-actions bot mentioned this pull request May 7, 2024
@alexandre-abrioux alexandre-abrioux deleted the fix-unwritable-error-stack branch May 7, 2024 18:36
Copy link
Contributor

github-actions bot commented May 7, 2024

Hi, @alexandre-abrioux! This PR has been published in v1.7.0-beta.1 release. Thank you for your contribution ❤️!

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.

None yet

2 participants