Closed Cherry closed 3 months ago
Hi @Cherry !
Using hono 3, observe a mixture of
success
and404z
response Using hono 4, observe a mixture ofsuccess
, andInternal Server Error
responses, with this logged:
I think the behavior is the same with both versions 3
and 4
. It will be a "mixture of success
and 404z
response". Can you try it again and let me know the result?
I would honestly expect the following function to throw a TypeScript issue:
Ahh, yeah. I also think it should be a TypeSript error, whether it is an async
handler or not. But it is very difficult or maybe impossible. Either way, I'll try to work on it. Thanks!
Sorry, I missed a critical piece in my reproduction above.
In my tests, I'm only ever hitting /foo
.
In version 3, I see a mixture of success
and the 404 on /foo
.
Whereas in version 4, I see a mixture of success
and then the previously mentioned error on /foo
. Very different behaviour.
Thanks for the reply!
@Cherry It's my pressure!
I would honestly expect the following function to throw a TypeScript issue
I've tried to make it your expected behavior, but I can't do it immediately. It maybe impossible. For now, I'll close this issue. Thanks.
Thanks @yusukebe. Is the behaviour difference between v3 and v4 expected when you return
nothing, and have a notFound
handler?
If so, it would be good to call this out in the migration guide for v3 -> v4.
Thanks @yusukebe. Is the behaviour difference between v3 and v4 expected when you
return
nothing, and have anotFound
handler?
Oh? I expect the behavior between v3 and v4 to be the same. Do you think there is a difference? Or are you saying that TypeScript Type matters?
There is a difference, yes.
Spin up the reproduction code above
Hit /foo
over and over
Using hono 3, observe a mixture of success
and 404z
response
Using hono 4, observe a mixture of success
, and Internal Server Error
responses, with this logged:
Context is not finalized. You may forget returning Response object or `await next()`
In v3, it seems that returning nothing in a handler triggers on the notFound
handler. But in v4, it does not.
The TypeScript type would have been a way to catch this in my migration, but the behaviour changed in v3 -> v4.
@Cherry
Thank you for your explanation. But one more. Sorry to ask you something that I doubt you. Did you run the following code and get an error?
import { Hono } from 'hono'
const app = new Hono()
app.get('/foo', async (context) => {
return
})
app.notFound((context) => {
return new Response('404z', {
status: 400
})
})
export default app
Because the following error message only occurs when using middleware, the above code may not cause an error.
Context is not finalized. You may forget returning Response object or `await next()`
Hmm, I'm not able to reproduce this anymore like I described in my initial issue, but I was able to do so reliably yesterday... very odd.
I will let you know and create a new issue if I find a way to reliably reproduce this again.
I will let you know and create a new issue if I find a way to reliably reproduce this again.
Please! Thanks!
What version of Hono are you using?
4.4.3
What runtime/platform is your app running on?
Cloudflare Workers
What steps can reproduce the bug?
Using the following code:
And then
npx wrangler dev
:Using hono 3, observe a mixture of
success
and404z
response Using hono 4, observe a mixture ofsuccess
, andInternal Server Error
responses, with this logged:What is the expected behavior?
Is this the intended behaviour? I feel like this does make more sense in version 4, and feels more semantically correct, but I didn't see it called out in the migration guide - let me know if I missed it.
Additional information
I would honestly expect the following function to throw a TypeScript issue:
If I remove the
async
declaration from the function, so it's just:I do then receive a error: