-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Node's internal errors aren't properly handled by koa's onerror handler in some situations #1466
Comments
I'm willing to do the patch if this is OK. |
There's a problem in jest: jestjs/jest#2549 node proposes util.isError but it's marked as deprecated for a long time (but it's still there!). Newer node versions propose |
@julienw can we use this syntax? |
I... Don't think this would work ? |
i hate old syntax, can we write it in mordern syntax? |
Koa supports older node versions so my understanding is that we want to keep using older syntax in this project. Moreover what you suggest doesn't work and I believe is not reliable. |
i just want to know its mordern syntax, can you tell me? |
In some cases, such as running tests in Jest, Node's internal errors such as PREMATURE_CLOSE (from the stream module) aren't properly handled by this code:
koa/lib/context.js
Line 113 in 9ee6584
A bit of debugging showed me that despite that they're Errors, the
instanceof Error
call returns false. My guess is that they're not using the sameError
object (different globals maybe?).As a result, this is the error I get:
This is working properly out of the jest environment though. The same error when running the server directly:
But this makes things confusing when finding such an error while working on tests for an app.
Would you be open changing this check using
Object.prototype.toString.call(err) !== '[object Error]'
? Or maybe use both checks to make sure we catch all cases? Any downsides?The text was updated successfully, but these errors were encountered: