-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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: assign message to error object in handle_error using Object.assign #11675
Conversation
🦋 Changeset detectedLatest commit: d4366ff The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
I just ran into this locally while looking into something else and was able to solve it with |
Does that work for workers too? |
The behaviour I see is quite strange. With a
The place where I originally saw this was with a try {
document.createComment('').appendChild(document.createElement('div'));
} catch (e) {
console.log(Object.getOwnPropertyDescriptor(e, 'message')); // undefined
e.message = 'overwritten'; // has no effect
console.log(e.message); // original message
Object.defineProperty(e, 'message', { value: 'overwritten' });
console.log(e.message); // 'overwritten'
throw e; // throws 'overwritten' in Chrome and Safari, original message in Firefox
} So there's absolutely no consistency between browsers, they're all just making it up as they go along. I'm not sure how to create a In other words I can't answer your question without knowing what error you were dealing with in the first place, because normal errors seem to work just fine (except that the overwritten message is ignored in some situations). |
I switched to using Object.assign |
did you test this with the error you encountered with a non-writable |
Co-authored-by: Rich Harris <[email protected]>
Co-authored-by: Rich Harris <[email protected]>
@Rich-Harris I'll try and find out from the user who reported it. |
Co-authored-by: Rich Harris <[email protected]>
Co-authored-by: Rich Harris <[email protected]>
It doesn't seem to be fixed. I created a laughably minimal repro. I guess the error is still thrown by the worker, even though one might expect it to be thrown by the main thread... Here is a something similar to what I had in my original code of the error in case its useful to have more substance. EDIT: I notice for some reason the stack trace might not be showing in the REPL, even though the error does. Here is my local dev stack trace:
runtime.js 287-290
|
Seems to be fixed just fine? Here's the second example running on this branch |
This uses Object.defineProperty to write to the error message instead.