-
-
Notifications
You must be signed in to change notification settings - Fork 34
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: referenceError on schema validation failure. #164
fix: referenceError on schema validation failure. #164
Conversation
…ing referenceError on schema validation failure.
Co-authored-by: Manuel Spigolon <[email protected]>
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.
Not sure why this works – an async hook should not return because a return essentially means returning the body/payload
Can you instead wrap the try finally
with a non-negated if?
const onSend = async (req) => {
const requestClient = extractRequestClient(req, transact)
if (requestClient) {
try {
if (!req[transactionFailedSymbol]) {
await requestClient.query('COMMIT')
}
} finally {
requestClient.release()
}
}
}
AFAIK in JS a function returns In pratical: async function foo() {}
foo().then((val)=>console.log({val}));
// {val: undefined}, Promise{<fulfilled>:undefined} I don't know if this is the right line, but https://github.com/fastify/fastify/blob/fc6bf5cb9f000ad4cda5e197f4fd22166a15dab9/lib/hooks.js#L288 here you can see that there is a check on payload to be different to The proposal change could be still about code style (personally I prefer to avoid nested code, but it's only an opinion and honestly I didn't check the other parts of code): should I still change it? |
Done in any case |
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.
Thank you!
You are right in your assessment of what's going on when undefined
is returned inside an async function in the context of hooks
At the time, I simply thought since this is a core plugin it should mirror the usage shown in the docs
Excuse me for taking your time with this
np: I like to go in deep and I had the opportunity to see other parts :) . Thank you for your review |
this solves #163
Checklist
npm run test
andnpm run benchmark
and the Code of conduct