-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
util: update isError with new Error.isError #57962
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
base: main
Are you sure you want to change the base?
Conversation
@@ -95,7 +95,7 @@ function isError(e) { | |||
// An error could be an instance of Error while not being a native error | |||
// or could be from a different realm and not be instance of Error but still | |||
// be a native error. | |||
return isNativeError(e) || e instanceof Error; | |||
return Error.isError ? Error.isError(e) : isNativeError(e) || e instanceof Error; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to ensure backward compatibility?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error.isError
should be the entirety of what isNativeError
does, and isNativeError should no longer be needed nor instanceof
used.
Wouldn't it make more sense to just remove isError
entirely, and use the ErrorIsError
primordial directly, and add "don't land" labels on this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, @ljharb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it! Do you think it is okay to continue with this PR and issue or would it be better to create a new one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems fine to me to adapt this PR to do that.
We should deprecate |
Just for some clarification: The former is exposed to userspace, and is going to be superseded by The latter is an internal utility that also checks |
If we have any internal errors that are instanceof Error but not proper errors (such that Error.isError returns false on them) then that's something we should fix asap. |
I believe |
They mentioned in the issue that |
It seems to be also used in comparisons |
So given all the context, do you think it would be best to just update the doc to use |
We don't need to reference I think the best path forward for this PR is to wait for the V8 update to land on Independently, a doc-only deprecation PR for |
Thanks @LiviaMedeiros for all the clarification! I agree that we should wait for v8 and I'll make the adjustment to all |
Refs 57961
Fixes: #57961
This PR updates the
isError
function inlib/internal/util.js
to use the nativeError.isError
method if it is available.