Skip to content

fix: route errors thrown after an async next to onError - #233

Open
draarivpatel-ui wants to merge 1 commit into
lukeed:mainfrom
draarivpatel-ui:fix/async-middleware-error
Open

draarivpatel-ui wants to merge 1 commit into
lukeed:mainfrom
draarivpatel-ui:fix/async-middleware-error

Conversation

@draarivpatel-ui

Copy link
Copy Markdown

Fixes #134.

loop() called each middleware without a try/catch, so an error thrown by a handler that was reached through an asynchronous next() escaped to the server as an uncaught exception instead of going to the error handler:

app.use((req, res, next) => setImmediate(next));
app.use(() => { throw new Error("boom") });

The exception is now caught and passed to onError, which responds with a 500 by default.

Tests

  • tape tests/polka.js: 234 passing, including a new case for this sequence. Without the change, the test process crashes with the uncaught error.

loop() invoked middleware without a try/catch, so an error thrown by a
handler reached through setImmediate(next) escaped to the server as an
uncaught exception instead of going to the error handler. Wrap each
invocation and pass the error to onError.
Copilot AI balanced review requested due to automatic review settings November 26, 2026 00:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Middleware Error handling incomplete

2 participants