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

Wrong instanceof behavior when extending Error #159

Closed
valeriangalliat opened this issue Jan 21, 2022 · 3 comments
Closed

Wrong instanceof behavior when extending Error #159

valeriangalliat opened this issue Jan 21, 2022 · 3 comments
Labels
bug Something isn't working fixed-in-next Fixed in next release

Comments

@valeriangalliat
Copy link

Hey! I'm running in the following inconsistency between Miniflare's engine (2.2.0) and other JS runtimes (including the Cloudflare runtime).

Consider the following worker:

class TestError extends Error {}

addEventListener('fetch', event => {
  event.respondWith(handleRequest(event.request))
})

async function handleRequest(request) {
  console.log(new Error() instanceof TypeError)
  console.log(new TypeError() instanceof Error)
  console.log(new TestError() instanceof Error)
  console.log(new TestError() instanceof TypeError)
  console.log(new TestError() instanceof TestError)
  console.log(new Error() instanceof TestError)
  console.log(new TypeError() instanceof TestError)

  return new Response('', {
    headers: { 'content-type': 'text/plain' },
  })
}

On Miniflare, it logs:

false
true
true
false
true
true
true

Whereas with wrangler dev (or just in Node.js or any browser), it logs:

false
true
true
false
true
false
false

The behaviour is correct for native errors but as soon as we extend Error, every error is considered to be instanceof our custom error on Miniflare.

Cheers!

@mrbbot mrbbot closed this as completed in ab60cad Jan 27, 2022
@mrbbot
Copy link
Contributor

mrbbot commented Jan 27, 2022

Uh oh! 😟 That's not good! Will be fixed in the next version. 👍

@mrbbot mrbbot added bug Something isn't working fixed-in-next Fixed in next release labels Jan 27, 2022
@mrbbot
Copy link
Contributor

mrbbot commented Feb 7, 2022

Hey! 👋 I've just released version 2.3.0 including a fix for this. You can find the full changelog here.

@valeriangalliat
Copy link
Author

valeriangalliat commented Feb 8, 2022

Awesome, thanks for the fix and the heads up! ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed-in-next Fixed in next release
Projects
None yet
Development

No branches or pull requests

2 participants