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
Fix invalid triggers of the uncaughtException handler #1710
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -674,6 +674,44 @@ test('GH-77 uncaughtException (default behavior)', function(t) { | |
}); | ||
}); | ||
|
||
// eslint-disable-next-line | ||
test('handleUncaughtExceptions should not call handler for internal errors', function(t) { | ||
SERVER.get('/', function(req, res, next) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a little bit confused about this test setup. I think we trying to verify restify/router errors (e.g., 404) don't trigger uncaught exceptions? If yes, should we just remove the get route and have the client do a get against a non-existent route? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There seems to be a behavior difference if you have no routes (which 404s) and having only GET routes and trying HEAD (results in MethodNotAllowed error). I agree that this makes the test confusing, but I think if the behavior difference should be fixed, it should be fixed separately. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gotcha - thanks for context! I expect this is related to CORS use cases - do you mind adding all of this as a comment to the test? Otherwise, it's a bit confusing to register the empty There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense. I added a comment and the assertion that you mentioned. |
||
// This route is not used for the test but at least one route needs to | ||
// be registered to Restify in order for routing logic to be run | ||
assert.fail('should not run'); | ||
}); | ||
|
||
SERVER.on('uncaughtException', function throwError(err) { | ||
t.ifError(err); | ||
t.end(); | ||
}); | ||
|
||
CLIENT.head('/', function(err, _, res) { | ||
t.ok(err); | ||
t.equal(res.statusCode, 405); | ||
t.end(); | ||
}); | ||
}); | ||
|
||
// eslint-disable-next-line | ||
test('handleUncaughtExceptions should not call handler for next(new Error())', function(t) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
SERVER.get('/', function(req, res, next) { | ||
next(new Error('I am not fatal')); | ||
}); | ||
|
||
SERVER.on('uncaughtException', function throwError(err) { | ||
t.ifError(err); | ||
t.end(); | ||
}); | ||
|
||
CLIENT.get('/', function(err, _, res) { | ||
t.ok(err); | ||
t.equal(res.statusCode, 500); | ||
t.end(); | ||
}); | ||
}); | ||
|
||
test('GH-77 uncaughtException (with custom handler)', function(t) { | ||
SERVER.on('uncaughtException', function(req, res, route, err) { | ||
res.send(204); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would still make errors emitted on objects bound to the domain (in this case
req
andres
) trigger anuncaughtException
event. It seems that would also be a problem?If we consider that is indeed not what the behavior of
handleUncaughtExceptions
should be, we should set the fourth parameter of_onHandlerError
totrue
only iferr.domainThrown === true
.@mridgway @DonutEspresso Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that behavior is consistent with Restify versions <7. I'm not sure what the original intention was though.
I agree that it would make more sense to filter to only uncaught exceptions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just verified that looking at the 6.x branch of this repository and this is correct. Thus I'm fine with keeping that behavior, at least for now.