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
Encapsulated error handling #3261
Conversation
@fastify/core I opened this one as draft to get early feedback. I would work to update the docs asap. All my console.logs are still there for ease of future debugging in this PR - I'll get this cleaned up. Let me know what you think. @sergiz PTAL |
@@ -508,7 +496,7 @@ function sendStream (payload, res, reply) { | |||
} | |||
|
|||
function onErrorHook (reply, error, cb) { | |||
if (reply.context.onError !== null && reply[kReplyErrorHandlerCalled] === true) { | |||
if (reply.context.onError !== null && !reply[kReplyNextErrorHandler]) { |
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.
Is the coercion check necessary? Or can it be === false
?
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.
The coercion is necessary. There might be a bug hiding somewhere around this check as it was one of the most troubling spot while doing this change.
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.
Let's add a comment to that effect.
This is now ready for review - I have just added docs. |
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.
Just one comment on doc but LGTM.
good job on this!
Co-authored-by: James Sumners <james@sumners.email>
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.
Amazing feature!
The first message incorrectly states that this PR fixes #2860. It doesn't make any changes in that regard.
Still incorrect verbs used. |
My reading of what is left of that issue is that throwing within error handlers was something not supported before. Maybe I misunderstood that issue. |
The inconsistencies described there are in regards to throwing errors in connection with whether handler/error handler are sync or async. This PR doesn't make any changes in that regard. I will open a PR which addresses these things during the weekend. |
Ok! Landing this now so you could use as a basis and not conflict. |
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.
A delayed LGTM!
As part of the error handling refactoring of #3261, we should not be setting a custom status code for validation routes. We should rely only on the error.statusCode property instead and leave the user full customization capabilities. Unfortunately a change was missed. Ref: #3261 Signed-off-by: Matteo Collina <hello@matteocollina.com>
As part of the error handling refactoring of #3261, we should not be setting a custom status code for validation routes. We should rely only on the error.statusCode property instead and leave the user full customization capabilities. Unfortunately a change was missed. Fixes: #4028 Ref: #3261 Signed-off-by: Matteo Collina <hello@matteocollina.com>
As part of the error handling refactoring of #3261, we should not be setting a custom status code for validation routes. We should rely only on the error.statusCode property instead and leave the user full customization capabilities. Unfortunately a change was missed. Fixes: #4048 Ref: #3261 Signed-off-by: Matteo Collina <hello@matteocollina.com>
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
This PR improves the error handling by allowing encapsulated error handler to call the upper-level error handler (or the fallback handler).
Ref #2860
Fixes #1436
Checklist
npm run test
andnpm run benchmark
and the Code of conduct