Skip to content

refactor: use built-in Error.isError - #2892

Merged
Tommy Nguyen (tido64) merged 1 commit into
trunkfrom
tido/use-builtin-iserror
Aug 4, 2026
Merged

refactor: use built-in Error.isError#2892
Tommy Nguyen (tido64) merged 1 commit into
trunkfrom
tido/use-builtin-iserror

Conversation

@tido64

@tido64 Tommy Nguyen (tido64) commented Jul 31, 2026

Copy link
Copy Markdown
Member

Description

Use built-in Error.isError instead of instanceof.

Note that this was recently introduced in Node 24.3. We cannot use it in public-facing code.

Platforms affected

  • Android
  • iOS
  • macOS
  • visionOS
  • Windows

Test plan

n/a

@JasonVMo Jason Morse (JasonVMo) left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we create a wrapper abstraction like?:

export function isError(e: unknown): e is Error {
  return e != null && (e as { isError?: unknown }).isError || e instanceof Error);
}

Generally we can catch the truthy value of isError which will match the new behavior but fall through to the older instance of behavior. It seems like the isError check effectively widens the type.

@tido64

Copy link
Copy Markdown
Member Author

Should we create a wrapper abstraction like?:

For this scenario specifically, we can use Error.isError because they're all for internal use only. There is exactly one instance, in public-facing code, where we use an abstraction:

function isErrorLike(e) {
return typeof e === "object" && e !== null && "name" in e && "message" in e;
}

Which can benefit from being replaced with Error.isError (because we don't care what kind of error it is). But we can change it when we bump minimum Node version.

@tido64
Tommy Nguyen (tido64) merged commit ca5a45f into trunk Aug 4, 2026
24 checks passed
@tido64
Tommy Nguyen (tido64) deleted the tido/use-builtin-iserror branch August 4, 2026 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants