Skip to content
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

throw errors when there is no return #2531

Open
bingtsingw opened this issue Apr 19, 2024 · 1 comment
Open

throw errors when there is no return #2531

bingtsingw opened this issue Apr 19, 2024 · 1 comment
Labels
enhancement New feature or request.

Comments

@bingtsingw
Copy link

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 bingtsingw added the enhancement New feature or request. label Apr 19, 2024
@bingtsingw bingtsingw changed the title throw type errors when there is no return throw errors when there is no return Apr 19, 2024
@yusukebe
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request.
Projects
None yet
Development

No branches or pull requests

2 participants