Skip to content

feat: add forwardError option to enable error forwarding to next middleware#2259

Merged
bjohansebas merged 9 commits intonextfrom
feature/forwardError
Feb 22, 2026
Merged

feat: add forwardError option to enable error forwarding to next middleware#2259
bjohansebas merged 9 commits intonextfrom
feature/forwardError

Conversation

@bjohansebas
Copy link
Member

Summary

While it works fine in Express, I’m not sure how it will behave in other frameworks, so testing is in progress.

What kind of change does this PR introduce?

Did you add tests for your changes?

Does this PR introduce a breaking change?

If relevant, what needs to be documented once your changes are merged or what have you already documented?

@codecov
Copy link

codecov bot commented Jan 29, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.92%. Comparing base (52e218d) to head (829ba0d).
⚠️ Report is 1 commits behind head on next.

Additional details and impacted files
@@            Coverage Diff             @@
##             next    #2259      +/-   ##
==========================================
+ Coverage   95.67%   96.92%   +1.25%     
==========================================
  Files          13       13              
  Lines         901      911      +10     
  Branches      263      266       +3     
==========================================
+ Hits          862      883      +21     
+ Misses         39       28      -11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

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

Yeah, not ever frameworks supports it, so we should add this option to docs and write which frameworks support it

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

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

Looks good, we can merge this, also let's add this in our doc

@alexander-akait
Copy link
Member

@bjohansebas Let's finish this todo, because it is easy, but for https://github.com/webpack/webpack-dev-middleware/pull/2255, we need more code

@alexander-akait
Copy link
Member

Let's fix lint, some test failed, but I think it is due hono, one test is unstable

"forwardError": {
"description": "Enable or disable forwarding errors to next middleware.",
"link": "https://github.com/webpack/webpack-dev-middleware#forwarderrors",
"type": "boolean"
Copy link
Member

Choose a reason for hiding this comment

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

Let's add this to our README too

Copy link
Member Author

Choose a reason for hiding this comment

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

yep!

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

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

Looks good, let's add this option to README and we can merge

});

// TODO: why koa and hono don't catch for their error handling when stream emit error?
(name === "koa" || name === "hono" ? it.skip : it)(
Copy link
Member Author

Choose a reason for hiding this comment

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

The behavior here in Hono and Koa is a bit strange, and it has to do with how they handle streams when sending the response. If an error is thrown, it’s not really captured, in fact, Hono would treat it as if forwardError were false.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I know it, but let's resolve it later, not critical for us

Copy link
Member Author

Choose a reason for hiding this comment

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

So do you want me to resolve it in another PR?

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

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

Feel free to merge

});

// TODO: why koa and hono don't catch for their error handling when stream emit error?
(name === "koa" || name === "hono" ? it.skip : it)(
Copy link
Member Author

Choose a reason for hiding this comment

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

So do you want me to resolve it in another PR?


Enable or disable forwarding errors to the next middleware. If `true`, errors will be forwarded to the next middleware, otherwise, they will be handled by `webpack-dev-middleware` and a response will be handled case by case.

This option don't work with hono, koa and hapi, because of the differences in error handling between these frameworks and express.
Copy link
Member Author

Choose a reason for hiding this comment

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

It's partially true, there are certain things that don’t work, but I think it’s better to say it doesn’t work first, and then once we know it works correctly, say that it does.

@bjohansebas bjohansebas marked this pull request as ready for review February 22, 2026 17:51
@bjohansebas bjohansebas changed the title [WIP]: feat: add forwardError option to enable error forwarding to next middleware feat: add forwardError option to enable error forwarding to next middleware Feb 22, 2026
@bjohansebas bjohansebas merged commit 4b475e8 into next Feb 22, 2026
13 of 14 checks passed
@bjohansebas bjohansebas deleted the feature/forwardError branch February 22, 2026 18:01
@alexander-akait
Copy link
Member

@bjohansebas

So do you want me to resolve it in another PR?

Yeah, it is in my TODO, we have the same problem with the one test (random fails)

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.

2 participants