Skip to content
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

Provide Node.js error constructors for Deno namespace errors #87

Open
kitsonk opened this issue Feb 18, 2022 · 3 comments
Open

Provide Node.js error constructors for Deno namespace errors #87

kitsonk opened this issue Feb 18, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@kitsonk
Copy link

kitsonk commented Feb 18, 2022

Currently Node.js SystemError doesn't work well with Deno.errors, for example, when a file is not found, Node.js produces a SystemError with a code of ENOENT which equates to a Deno.errors.NotFound, but err instanceof Deno.errors.NotFound works under Deno, but fails under Node.js.

We should consider providing a [Symbol.hasInstance] implementation for a special class of Deno.errors in the shim that would do further analysis on the Node.js error instances and see if it maps back to a Deno error, so instanceof operator can work.

@hyp3rflow
Copy link
Contributor

How about implementing like this?

export class NotFound extends Error {
  code = "ENOENT";
  static [Symbol.hasInstance](error: any): boolean {
    return error.hasOwnProperty('errno') && util.getSystemErrorName(error.errno) === "ENOENT";
  }
}

@wojpawlik
Copy link
Contributor

return error instanceof Error && error.code === "ENOENT"

@hyp3rflow
Copy link
Contributor

@wojpawlik oh thanks my mistake :q

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants