Skip to content

🔥 feat: Support Express-style next callback handlers#4029

Merged
ReneWerner87 merged 3 commits intomainfrom
update-handler-signatures-in-adapter.go
Jan 24, 2026
Merged

🔥 feat: Support Express-style next callback handlers#4029
ReneWerner87 merged 3 commits intomainfrom
update-handler-signatures-in-adapter.go

Conversation

@gaby
Copy link
Member

@gaby gaby commented Jan 24, 2026

Motivation

  • Support Express-style next callbacks that accept errors so middleware written for Express-like ecosystems interoperates correctly with Fiber.
  • Ensure error propagation is deterministic: next(nil) should continue the chain while a non-nil next(err) should short-circuit, with a clear precedence between handler-returned errors and next errors.

Description

  • Extend toFiberHandler/adaptExpressHandler to recognize additional Express-style signatures (func(Req, Res, func(error)), func(Req, Res, func(error)) error, func(Req, Res, func(error) error), and func(Req, Res, func(error) error) error) and wire them into the adapter.
  • Implement logic so next(nil) calls c.Next() and a non-nil next(err) short-circuits and returns the provided error, while handler-returned errors take precedence when present.
  • Add tests in adapter_test.go that verify next(nil) continues the chain, next(err) short-circuits, and deterministic precedence between handler return errors and next errors.
  • Update documentation in docs/partials/routing/handler.md and docs/whats_new.md to enumerate the new handler cases and describe the error-handling behavior.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 24, 2026

Note

Other AI code review bot(s) detected

CodeRabbit 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.

Walkthrough

This 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

Cohort / File(s) Summary
Express Handler Adapter Extension
adapter.go
Expanded Express-style signature support from cases (3)-(8) to (3)-(12) in toFiberHandler/adaptExpressHandler. Added four new cases handling error-accepting next callbacks: func(Req, Res, func(error)), func(Req, Res, func(error)) error, func(Req, Res, func(error) error), and func(Req, Res, func(error) error) error. Renumbered net/http cases to (13)-(15) and fasthttp to (16)-(17).
Test Suite & Scaffolding
adapter_test.go
Introduced withRouteHandlers test helper to consolidate repetitive route initialization and cleanup. Added substantial test coverage for Express-style handler chaining, error propagation, and next-callback behavior across the new signature variants.
Documentation Updates
docs/partials/routing/handler.md, docs/whats_new.md
Updated handler case enumeration from 13 to 17 cases. Expanded Express-style section from cases 3-8 to 3-12 with behavioral notes on error propagation through next callbacks. Added clarification on how next(err) is wired to c.Next() and handler return value interactions.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

📒 Documentation

Suggested reviewers

  • sixcolors
  • efectn
  • grivera64
  • ReneWerner87

Poem

🐰 Four new signatures hopped through the door,
Error callbacks we couldn't ignore—
Next whispers secrets, then handlers reply,
Chain links with grace as errors fly by! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 4.76% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main feature being added: support for Express-style next callback handlers with error parameter support.
Description check ✅ Passed The description is well-structured with clear motivation, implementation details, test coverage, and documentation updates. It covers required sections including motivation, technical description, testing approach, and documentation changes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ReneWerner87 ReneWerner87 added this to the v3 milestone Jan 24, 2026
@ReneWerner87 ReneWerner87 added this to v3 Jan 24, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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 next callbacks that are aware of errors. This allows for more seamless integration with middleware from Express-like ecosystems, providing deterministic error propagation where next(nil) continues the chain and next(err) short-circuits. The changes also define clear precedence for error handling, prioritizing handler-returned errors.

Highlights

  • Enhanced Express-style Handler Support: Fiber's adapter now recognizes Express-style next callbacks that accept error arguments, improving interoperability with Express-like middleware.
  • Deterministic Error Propagation: Implemented clear rules for next(nil) to continue the handler chain and next(err) to short-circuit, ensuring predictable error flow.
  • Error Precedence Logic: Established that errors returned directly by a handler take precedence over errors passed to the next callback.

🧠 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 Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gaby gaby changed the title 🐛 bug: document error-aware express adapter handlers 🔥 feat: Support Express-style next callback handlers Jan 24, 2026
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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
Copy link

codecov bot commented Jan 24, 2026

Codecov Report

❌ Patch coverage is 76.27119% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.13%. Comparing base (8b09b22) to head (3be7865).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
adapter.go 76.27% 9 Missing and 5 partials ⚠️
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     
Flag Coverage Δ
unittests 91.13% <76.27%> (-0.17%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 next callbacks that accept error parameters
  • Implemented error propagation logic where next(nil) continues the chain and next(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

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

⚠️ 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.

@gaby gaby marked this pull request as ready for review January 24, 2026 13:00
@gaby gaby requested a review from a team as a code owner January 24, 2026 13:00
@gaby gaby removed the ☢️ Bug label Jan 24, 2026
@ReneWerner87 ReneWerner87 merged commit 52eaa82 into main Jan 24, 2026
17 of 19 checks passed
@ReneWerner87 ReneWerner87 deleted the update-handler-signatures-in-adapter.go branch January 24, 2026 17:13
@github-project-automation github-project-automation bot moved this to Done in v3 Jan 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants