🔥 feat: Support Express-style next callback handlers#4029
Conversation
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughThis PR extends Fiber's handler adapter to support additional Express-style request handler signatures, specifically those accepting error callbacks and returning errors. The changes span core adapter logic, comprehensive test coverage with a new helper, and corresponding documentation updates reflecting the expanded case taxonomy. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary of ChangesHello @gaby, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances Fiber's handler adaptation capabilities by introducing support for Express-style Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request extends the Express-style handler adapter to support four new signatures that include error-aware next callbacks. This is a great addition for interoperability with Express-like middleware. The implementation correctly handles error propagation and precedence. The changes are well-tested and documented. My feedback focuses on reducing code duplication in both the implementation and the new tests to improve long-term maintainability.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4029 +/- ##
==========================================
- Coverage 91.30% 91.13% -0.17%
==========================================
Files 119 119
Lines 11051 11101 +50
==========================================
+ Hits 10090 10117 +27
- Misses 609 626 +17
- Partials 352 358 +6
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR adds support for Express-style next callback handlers that accept errors, enabling better interoperability with Express-like middleware ecosystems. The implementation ensures deterministic error propagation where next(nil) continues the middleware chain while next(err) short-circuits, with handler-returned errors taking precedence.
Changes:
- Added four new Express-style handler signatures (cases 9-12) supporting
nextcallbacks that accepterrorparameters - Implemented error propagation logic where
next(nil)continues the chain andnext(err)short-circuits - Added comprehensive test coverage for all new handler types and error scenarios
- Updated documentation to describe the new handler cases and error-handling behavior
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| adapter.go | Added four new Express-style handler cases (9-12) with error-accepting next callbacks and implemented proper error propagation logic |
| adapter_test.go | Added helper function withRouteHandlers and comprehensive tests covering all new handler signatures and error scenarios |
| docs/whats_new.md | Updated handler table and description to document the four new Express-style handler cases |
| docs/partials/routing/handler.md | Updated documentation to enumerate new handler cases and describe error-handling behavior |
There was a problem hiding this comment.
⚠️ Performance Alert ⚠️
Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.50.
| Benchmark suite | Current: 3be7865 | Previous: ff3fa6e | Ratio |
|---|---|---|---|
BenchmarkEncodeitem-4_middleware_csrf - MB/s |
227.27 MB/s |
148.04 MB/s |
1.54 |
This comment was automatically generated by workflow using github-action-benchmark.
Motivation
nextcallbacks that accept errors so middleware written for Express-like ecosystems interoperates correctly with Fiber.next(nil)should continue the chain while a non-nilnext(err)should short-circuit, with a clear precedence between handler-returned errors andnexterrors.Description
toFiberHandler/adaptExpressHandlerto recognize additional Express-style signatures (func(Req, Res, func(error)),func(Req, Res, func(error)) error,func(Req, Res, func(error) error), andfunc(Req, Res, func(error) error) error) and wire them into the adapter.next(nil)callsc.Next()and a non-nilnext(err)short-circuits and returns the provided error, while handler-returned errors take precedence when present.adapter_test.gothat verifynext(nil)continues the chain,next(err)short-circuits, and deterministic precedence between handler return errors andnexterrors.docs/partials/routing/handler.mdanddocs/whats_new.mdto enumerate the new handler cases and describe the error-handling behavior.