| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
| @@ -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.
Do we need to ensure backward compatibility?
Sorry, something went wrong.
There was a problem hiding this comment.
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?
Sorry, something went wrong.
There was a problem hiding this comment.
+1, @ljharb
Sorry, something went wrong.
There was a problem hiding this comment.
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?
Sorry, something went wrong.
There was a problem hiding this comment.
seems fine to me to adapt this PR to do that.
Sorry, something went wrong.
There was a problem hiding this comment.
We still want to match errors that are not regular ones. The wild has many examples of these, so we should keep instanceof.
Sorry, something went wrong.
|
We should deprecate .isError like .isArray |
Sorry, something went wrong.
|
Just for some clarification: The former is exposed to userspace, and is going to be superseded by Error.isError(). The latter is an internal utility that also checks instanceof Error which can be true even if Error.isError() is not (and vice versa). |
Sorry, something went wrong.
|
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. |
Sorry, something went wrong.
|
I believe internalUtil.isError() is used only in assert, inspect, repl, and test_runner. All of these have reasons to expect non-errors with Error in prototype chain sent from wild userspace, and internalUtil.isError() helps with covering this case. |
Sorry, something went wrong.
They mentioned in the issue that util.isError is in fact EOL |
Sorry, something went wrong.
It seems to be also used in comparisons |
Sorry, something went wrong.
|
So given all the context, do you think it would be best to just update the doc to use Error.IsError (and not the reference to use Object.prototype.toString(arg) === '[object Error]' || arg instanceof Error) and wait for the new version to arrive to make it easier to find out if there are any cases outside of those mentioned that we expect to be non-errors? |
Sorry, something went wrong.
util.isError() was part of the public API, which is indeed no longer the case. internalUtil.isError() is an internal helper function that should still exist.
We don't need to reference || arg instanceof Error in the docs at all, since we aren't exposing this logic to userland. I think the best path forward for this PR is to wait for the V8 update to land on main, rebase on it, and then replace all occurrences of isNativeError() with ErrorIsError(). This change would be purely internal: no documentation changes or further justification needed, provided nothing breaks. Independently, a doc-only deprecation PR for util.types.isNativeError() can be opened. |
Sorry, something went wrong.
|
Thanks @LiviaMedeiros for all the clarification! I agree that we should wait for v8 and I'll make the adjustment to all isNativeErrors and I'll also wait to open the issue related to its depreciation, it seemed simpler to me. |
Sorry, something went wrong.
I'm seeing a >50% performance regression for Error.isError over util.types.isNativeError in the current RC. custom/type-check-nativeerror.js n=1000000 handler="error-iserror" type="native-error": 55,167,312.528783545 custom/type-check-nativeerror.js n=1000000 handler="isnativeerror" type="native-error": 127,300,251.90173846 custom/type-check-nativeerror.js n=1000000 handler="error-iserror" type="native-error-crossrealm": 50,549,863.72514987 custom/type-check-nativeerror.js n=1000000 handler="isnativeerror" type="native-error-crossrealm": 123,061,852.73311144 custom/type-check-nativeerror.js n=1000000 handler="error-iserror" type="non-native-error": 53,863,525.66184942 custom/type-check-nativeerror.js n=1000000 handler="isnativeerror" type="non-native-error": 117,042,527.28524657 I don't think that deprecation should really be considered unless this gets addressed upstream.
As a side note, ErrorIsError will not be exposed as a primordial while it remains a flagged feature in V8. |
Sorry, something went wrong.
|
This PR can't land until it's unflagged, regardless. |
Sorry, something went wrong.
|
Hey, I'm doing some local tests, and indeed, we can't change our internal.isError to use Error.isError because, like @LiviaMedeiros mentioned, we expect some non-errors, and it starts to break a lot of internals like assert. Besides this, I'm not seeing any use of isNativeError outside that context. |
Sorry, something went wrong.
Codecov ReportAttention: Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
@@ Coverage Diff @@
## main #57962 +/- ##
==========================================
- Coverage 90.12% 90.06% -0.06%
==========================================
Files 629 629
Lines 186622 186638 +16
Branches 36624 36568 -56
==========================================
- Hits 168186 168093 -93
- Misses 11217 11349 +132
+ Partials 7219 7196 -23
... and 37 files with indirect coverage changes 🚀 New features to boost your workflow:
|
Sorry, something went wrong.
|
Okay, so keeping e instanceof Error and replacing isNativeError with ErrorisError seems right! I'll also open another PR to make the deprecation of isNativeError. |
Sorry, something went wrong.
Hey @Renegade334 sorry but what do you mean by "flagged feature in V8"? |
Sorry, something went wrong.
The Error.isError API, while enabled by default now in Node 24.0.0 is still only conditionally enabled in v8 using a flag (js-error-iserror), putting it in a special category. When Node.js builds the primordials object the Error.isError(...) function function not actually exist yet on the Error object. It might be a while before it is Just Available without the flag. |
Sorry, something went wrong.
Thank you for that explanation! |
Sorry, something went wrong.
We can keep it with a blocked tag since we need to wait for this unflagging |
Sorry, something went wrong.
|
This pull request has been marked as stale due to 210 days of inactivity. |
Sorry, something went wrong.
|
This pull request has been marked as stale due to 90 days of inactivity. |
Sorry, something went wrong.
|
it's been a while 👀 |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Refs 57961
Fixes: #57961
This PR updates the isError function in lib/internal/util.js to use the native Error.isError method if it is available.