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
Validate and throws a custom error when attempting to register invalid hook functions #4332
Validate and throws a custom error when attempting to register invalid hook functions #4332
Conversation
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.
lgtm
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.
Thanks for the pr!
Can you use/create a custom error like we are doing for every other Fastify custom error? See here.
Thanks!
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.
It seems that we have this error already:
Lines 98 to 103 in acba25a
FST_ERR_HOOK_INVALID_HANDLER: createError( | |
'FST_ERR_HOOK_INVALID_HANDLER', | |
'The hook callback must be a function', | |
500, | |
TypeError | |
), |
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.
lgtm
@delvedor I think the error message I added (e.g "onSend hook should be a function, instead got undefined") can be more informative than the error message in the existing error "The hook callback must be a function", it also provides the following additional information which may helps in debugging:
In my latest commit, I modified the error message of the existing error instead. |
I see your point, then I'll suggest to update the existing error message :)
This is a valid point, but we have error codes for a reason. Error messages are the human-friendly version of them which is subjected to change. |
the existing error message is updated in my last commit 👍 |
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.
lgtm
@delvedor PTAL |
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.
Nice
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.
LGTM
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. |
Handles this issue, a hook is invalid if it is not of type function because it needs to bind with the fastify instance.
This PR will add validation for the hook functions passed in the
options
argument of route registration functions.Checklist
npm run test
andnpm run benchmark
and the Code of conduct