-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
Add a way to downgrade custom errors to native errors (limitation of HTML structured clone algorithm) #37988
Comments
There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment. For more information on how the project manages feature requests, please consult the feature request management document. |
There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment. For more information on how the project manages feature requests, please consult the feature request management document. |
I still think this is very valid, it's just that Workers are still rarely used in the grand scheme of the Node.js ecosystem. In addition you also need to extend the |
There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment. For more information on how the project manages feature requests, please consult the feature request management document. |
My dearest bot, this is still a relevant feature request. But my comment above still holds true, Workers + custom error class are a rare combination, but I'm sure people are already running into it and don't realize (e.g. if you use ava and use custom errors you will). |
There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment. For more information on how the project manages feature requests, please consult the feature request management document. |
There has been no activity on this feature request and it is being closed. If you feel closing this issue is not the right thing to do, please leave a comment. For more information on how the project manages feature requests, please consult the feature request management document. |
Same problem here. I have validation errors and a simple if like this: |
Restoring a custom class is almost impossible to do right. There is no native |
@BridgeAR I want to point out that this is not what this issue is about. I never talked about restoring the original class, that is impossible. But currently you get a plain object and not an error at all. |
Is your feature request related to a problem? Please describe.
I'm using Worker Threads. When the thread crashes with a custom error it is not properly serialized. The following demonstrates the difference (using
postMessage
, the result is the same as with theerror
event). I'm usingverror
because it's very popular library, but this applies to everything that is not a nativeError
.index.js
worker.js
This can be very unexpected and the stack information is lost. In reality the problem I'm running into is even worse. It's not with verror but with a custom SqliteError that has it's properties as
enumerable: false
. This means only an empty{}
will arrive in the other thread. So even if I've never thrown anything that is not anError
I still end up with not-an-error inside theerror
event.Describe the solution you'd like
According to MDN the fact that
Error
is serializable at all is already a blessingAnd I assume it's not possible to serialize custom errors in general because the class might not even exist in the other thread.
What I wish for is one of these two:
Error
. I'm not suggesting doing this for arbitrary objects and MDN says "The prototype chain is not walked or duplicated.". But I think subclasses ofError
deserve that special treatmentvalueOf
andtoJSON
that can be used to aid the cloning algorithm, so downgrading the Error would be in the hands of library authorsDescribe alternatives you've considered
I've tried downgrading the errors in
uncaughtException
event and throwing the nativeError
, but you cannot have an uncaught exception insideuncaughtException
and have the thread crash with the new error instead.And this solutions doesn't help others debugging the same issue and only seeing
{}
on their error logs.The text was updated successfully, but these errors were encountered: