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

[hono/combine] Function skipped in some() inside every() is still called #3898

Closed
satoshun00 opened this issue Feb 7, 2025 · 1 comment · Fixed by #3905
Closed

[hono/combine] Function skipped in some() inside every() is still called #3898

satoshun00 opened this issue Feb 7, 2025 · 1 comment · Fixed by #3905
Labels

Comments

@satoshun00
Copy link
Contributor

satoshun00 commented Feb 7, 2025

What version of Hono are you using?

4.7.0

What runtime/platform is your app running on? (with version if possible)

Node.js

What steps can reproduce the bug?

Here is a reproducible example:
https://stackblitz.com/edit/node-dtmqxwzv?file=index.ts

import { serve } from '@hono/node-server';
import { Hono } from 'hono';
import { every, some } from 'hono/combine';

const middleware = every(
  some(
    async (_, next) => {
      console.log('middleware 1');
      await next();
    },
    async (_, next) => {
      console.log('middleware 2', 'should not be called'); // 👈️ Called after "error thrown"
      await next();
    }
  ),
  () => {
    console.log('error thrown');
    throw new Error('some error');
  }
);

const app = new Hono();
app.use(middleware);
app.get('/', (c) => {
  return c.text('ok');
});

serve(app);

What is the expected behavior?

middleware 2 should be skipped.

What do you see instead?

middleware 2 called after "error thrown".

Additional information

This issue is also reproducible with the following code. It seems that middleware skipped by some() is called later, regardless of whether every() is used.

const middleware: MiddlewareHandler = async (c, _next) => {
  await some(
    async (_, next) => {
      console.log('middleware 1');
      await next();
    },
    async (_, next) => {
      console.log('middleware 2', 'should not be called');
      await next();
    }
  )(c, async () => {
    console.log('error thrown');
    throw new Error('some error');
  });
};
@satoshun00
Copy link
Contributor Author

satoshun00 commented Feb 7, 2025

I identified the issue and submitted a fix in a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
1 participant