hono icon indicating copy to clipboard operation
hono copied to clipboard

throw errors when there is no return

Open bingtsingw opened this issue 10 months ago • 1 comments

What is the feature you are proposing?

hono will throw a runtime error of Context is not finalized if there is no return c.xxx(), but there is no typescript check, some functions return c.body(null, 204), which is easy to be forgotten. So I think if we can add some type check or eslint rules to prevent no return expression

bingtsingw avatar Apr 19 '24 04:04 bingtsingw

Hi @bingtsingw

I also want to have the feature!

Currently, it throws a TypeScript error when a handler is not async.

CleanShot 2024-04-20 at 16 47 49@2x

But if it is an async function, we can't make it throw an error because we have to treat the middleware handler as the same as the handler. For example, the code should not throw an error.

app.get('/', async (c, next) => {
  await next()
})

So an async handler does not throw an error.

CleanShot 2024-04-20 at 16 52 10@2x

Making it throw an error will be difficult or impossible, I think.

yusukebe avatar Apr 20 '24 07:04 yusukebe