Skip to content

🔥 feat: Add PanicHandler in recover middleware#4110

Merged
ReneWerner87 merged 19 commits into
gofiber:mainfrom
JonasDoe:recover_with_error_creator
Feb 26, 2026
Merged

🔥 feat: Add PanicHandler in recover middleware#4110
ReneWerner87 merged 19 commits into
gofiber:mainfrom
JonasDoe:recover_with_error_creator

Conversation

@JonasDoe

@JonasDoe JonasDoe commented Feb 24, 2026

Copy link
Copy Markdown
Contributor

Description

If added an PanicHandler field to the Config of the recover middleware. Thre reason: Right now, panics recovered by the middleware will expose internals when they get returned. While the ErrorHandler in the fiber.Config allows me to change this behavior, at this point I've no way to actually detect whether the error is intended to be returned int he response or not.
With the PanicHandler, I can create return a dedicated, internal error type so the ErrorHandler know to handle it differently, or I can return an error which got already cleared of all internals.

Fixes #4109

Changes introduced

List the new features or adjustments introduced in this pull request. Provide details on benchmarks, documentation updates, changelog entries, and if applicable, the migration guide.

  • Benchmarks: Describe any performance benchmarks and improvements related to the changes.
  • Documentation Update: The documention didn't cover the config details before, so I didn't touch it.
  • Changelog/What's New: Custom PanicHandler for the recover middleware.
  • Migration Guide: None-breaking. The default is the original behavior.
  • API Alignment with Express: There's no recovery default in Express, and Go errors don't mirror JavaScript Errors anyway.
  • API Longevity: Discuss the steps taken to ensure that the new or updated APIs are consistent and not prone to breaking changes.
  • Examples:
    app.Use(recover.New(recover.Config{PanicHandler: func(c fiber.Ctx, r any) error {
        return fiber.ErrInternalServerError
    }}))

Type of change

Please delete options that are not relevant.

  • Enhancement (improvement to existing features and functionality)
  • Code consistency (non-breaking change which improves code reliability and robustness)

Checklist

Before you submit your pull request, please make sure you meet these requirements:

  • Followed the inspiration of the Express.js framework for new functionalities, making them similar in usage.
  • Conducted a self-review of the code and provided comments for complex or critical parts.
  • Updated the documentation in the /docs/ directory for Fiber's documentation.
  • Added or updated unit tests to validate the effectiveness of the changes or new features.
  • Ensured that new and existing unit tests pass locally with the changes.
  • Verified that any new dependencies are essential and have been agreed upon by the maintainers/community.
  • Aimed for optimal performance with minimal allocations in the new code.
  • Provided benchmarks for the new code to analyze and improve upon: It did not change:
    ok github.com/gofiber/fiber/v3/middleware/recover 0.015s

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @JonasDoe, 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 enhances the recover middleware in Fiber by introducing a new ErrorCustomizer configuration option. This feature addresses the issue of internal details being exposed when panics are recovered, providing a mechanism for developers to define how recovered panics are transformed into error types. This allows for more secure and controlled error handling, preventing sensitive information from being inadvertently returned in API responses.

Highlights

  • Customizable Error Handling for Panics: Introduced an ErrorCustomizer field to the recover.Config struct, allowing developers to define a custom function to transform recovered panic values into error types. This prevents internal details from being exposed in responses.
  • Default Error Customization: Provided a defaultErrorCustomizer function that converts any recovered panic value into a standard error, ensuring a consistent default behavior if no custom function is provided.
  • Integration with Global Error Handler: Modified the recover middleware to utilize the ErrorCustomizer when a non-error panic is caught, enabling better integration with Fiber's global ErrorHandler for more controlled and secure error responses.
Changelog
  • middleware/recover/config.go
    • Added ErrorCustomizer field to the Config struct.
    • Initialized ErrorCustomizer with defaultErrorCustomizer in ConfigDefault.
  • middleware/recover/recover.go
    • Implemented defaultErrorCustomizer to convert recovered panic values into error types.
    • Modified the recover middleware logic to utilize the ErrorCustomizer when a non-error panic is caught.
  • middleware/recover/recover_test.go
    • Updated the Test_Recover function to include a custom ErrorCustomizer in the recover middleware configuration.
    • Adjusted assertions to reflect the new error message format produced by the customizer.
Activity
  • Self-reviewed the code changes.
  • Updated the changelog to reflect the new customizable errors for the recover middleware.
  • Provided an example of how to use the new ErrorCustomizer in the PR description.
  • Confirmed that unit tests pass locally.
  • Conducted benchmarks for the recover middleware.
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.

@ReneWerner87 ReneWerner87 added this to v3 Feb 24, 2026
@ReneWerner87 ReneWerner87 added this to the v3 milestone Feb 24, 2026
@coderabbitai

coderabbitai Bot commented Feb 24, 2026

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Adds an ErrorCustomizer callback to the recover middleware Config, wires defaultErrorCustomizer as the default, and invokes cfg.ErrorCustomizer(c, r) in the panic recovery path to convert recovered values to an error before calling the global error handler.

Changes

Cohort / File(s) Summary
Recovery Configuration
middleware/recover/config.go
Adds ErrorCustomizer func(c fiber.Ctx, r any) error to Config, sets ConfigDefault.ErrorCustomizer = defaultErrorCustomizer, and ensures configDefault populates a non-nil customizer.
Recovery Logic
middleware/recover/recover.go
Adds unexported defaultErrorCustomizer(_ fiber.Ctx, r any) error and replaces inline recovered-value-to-error construction with cfg.ErrorCustomizer(c, r) in the deferred panic handler.
Recovery Tests
middleware/recover/recover_test.go
Updates tests to import fmt, pass Config{ErrorCustomizer: ...} to New, and assert on the customized (prefixed) error message.
Docs
docs/whats_new.md
Adds Recover middleware entry and documents the new ErrorCustomizer option in the v3 "What's New" and migration guide sections.

Sequence Diagram(s)

mermaid
sequenceDiagram
participant Client
participant RecoverMiddleware as RecoverMiddleware
participant RouteHandler as RouteHandler
participant ErrorHandler as GlobalErrorHandler

Client->>RecoverMiddleware: HTTP request
RecoverMiddleware->>RouteHandler: call next handler
RouteHandler-->>RecoverMiddleware: panic (recovered value)
RecoverMiddleware->>RecoverMiddleware: cfg.ErrorCustomizer(c, recoveredValue)
RecoverMiddleware->>ErrorHandler: pass customized error
ErrorHandler->>Client: HTTP response (mapped from error)

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

📒 Documentation

Suggested reviewers

  • gaby
  • sixcolors
  • efectn
  • ReneWerner87

Poem

🐇 I caught a panic on the run,

I shaped it gently, hid what's done,
A tidy error, wrapped and neat,
Sent downstream with silent feet,
— hopped away, the fix is fun ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (2 warnings, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ⚠️ Warning The PR title mentions 'PanicHandler' but the actual feature adds an 'ErrorCustomizer' field. The title is misleading and does not accurately describe the main change in the changeset. Update the title to accurately reflect the feature: 'Add ErrorCustomizer to recover middleware' or similar, avoiding the emoji and generic 'feat:' prefix for clarity.
Description check ❓ Inconclusive PR description contains typos and inconsistencies with actual changes (refers to 'PanicHandler' when field is 'ErrorCustomizer'); template mostly followed but some sections incomplete or generic. Clarify whether field is named 'PanicHandler' or 'ErrorCustomizer'; fix typos ('Thre' → 'The', 'int he' → 'in the'); provide specific details on benchmarks and API longevity considerations.
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Code changes fully implement the ErrorCustomizer feature as required by issue #4109: config field added, default behavior preserved, customization enables error transformation to hide internals.
Out of Scope Changes check ✅ Passed All changes directly relate to the ErrorCustomizer feature: config field, helper function, test updates, and docs. No unrelated or out-of-scope modifications detected.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds an ErrorCustomizer hook to Fiber’s recover middleware so callers can sanitize/replace errors produced from recovered panics before they reach the app-level ErrorHandler.

Changes:

  • Introduces Config.ErrorCustomizer with a default implementation.
  • Updates recover middleware to call the customizer when a non-error panic value is recovered.
  • Updates recover middleware unit test to exercise the new config surface.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
middleware/recover/config.go Adds ErrorCustomizer to recover.Config and wires it into ConfigDefault.
middleware/recover/recover.go Adds default customizer and uses it when recovering non-error panic values.
middleware/recover/recover_test.go Updates the main recover test to configure ErrorCustomizer and changes expected behavior.

Comment thread middleware/recover/recover_test.go Outdated
Comment thread middleware/recover/config.go Outdated
Comment thread middleware/recover/config.go Outdated
Comment thread middleware/recover/recover.go Outdated

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

Copy link
Copy Markdown
Contributor

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 enhances the recover middleware by introducing an ErrorCustomizer to allow users to mask internal panic details and prevent leaking implementation specifics. However, a critical vulnerability exists: if a partial Config struct is provided, the ErrorCustomizer field can remain uninitialized (nil), leading to a nil pointer dereference and an application panic, which can be exploited for a Denial of Service. Additionally, the current logic bypasses the customizer if the panic value is already an error, limiting its usefulness, and the configDefault helper is missing a crucial nil-check for the new field. There's also a mismatch in the provided test case between the customizer and its assertions.

Comment thread middleware/recover/recover.go Outdated
Comment thread middleware/recover/config.go Outdated
Comment thread middleware/recover/recover_test.go Outdated
Comment thread middleware/recover/recover.go Outdated
@gaby

gaby commented Feb 24, 2026

Copy link
Copy Markdown
Member

@JonasDoe Please check the comments above. There's a few issues with the implementation.

  • The name ErrorCustomizer needs to be changed.
  • The docs/middleware/recover.md needs to be updated
  • The docs/whats_new.md needs to be updated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@middleware/recover/recover_test.go`:
- Around line 16-24: The test currently uses require.Equal inside the
ErrorHandler closure which violates the linter rule against assertions in HTTP
handlers and also compares against the panic string while ErrorCustomizer
returns fiber.ErrInternalServerError; change the handler to remove require and
instead call t.Errorf to report failures, and assert that err equals
fiber.ErrInternalServerError (or err == fiber.ErrInternalServerError) rather
than the panic message; update the ErrorHandler closure and its assertion
accordingly so the handler reports via t.Errorf and validates the error from
ErrorCustomizer.

In `@middleware/recover/recover.go`:
- Around line 38-42: The panic recovery path calls cfg.ErrorCustomizer without
checking for nil, which can cause a secondary panic on non-error panics; update
configDefault() to set a default ErrorCustomizer (same pattern used for
StackTraceHandler) so ErrorCustomizer is never nil, or alternatively add a
nil-check before calling cfg.ErrorCustomizer in the recover logic (the code
around ErrorCustomizer and r.(error) in recover.go) to only call it when non-nil
and otherwise set a sensible default error value.

ℹ️ Review info

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 082e205 and 4011eec.

📒 Files selected for processing (3)
  • middleware/recover/config.go
  • middleware/recover/recover.go
  • middleware/recover/recover_test.go

Comment thread middleware/recover/recover_test.go Outdated
Comment thread middleware/recover/recover.go Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
middleware/recover/recover_test.go (1)

16-24: ⚠️ Potential issue | 🔴 Critical

require inside ErrorHandler violates the linter rule, and the assertion compares the wrong error.

Two unresolved problems in Test_Recover:

  1. Linter violationrequire.Equal inside the ErrorHandler closure panics the test goroutine on failure instead of failing the test; use t.Errorf inside handlers.
  2. Wrong assertion – The custom ErrorCustomizer returns fiber.ErrInternalServerError, so ErrorHandler receives that error ("Internal Server Error"), not the panic string. The assertion against "[RECOVERED]: Hi, I'm an error!" will always fail.
🐛 Proposed fix
	ErrorHandler: func(c fiber.Ctx, err error) error {
-		require.Equal(t, "[RECOVERED]: Hi, I'm an error!", err.Error())
+		if err == nil || err.Error() != fiber.ErrInternalServerError.Error() {
+			t.Errorf("expected %q, got %v", fiber.ErrInternalServerError.Error(), err)
+		}
		return c.SendStatus(fiber.StatusTeapot)
	},

Based on learnings: in the Fiber codebase, the linter does not allow require assertions from within HTTP handlers; use t.Fatalf, t.Errorf, or similar testing.T methods instead.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@middleware/recover/recover_test.go` around lines 16 - 24, Test_Recover's
ErrorHandler closure uses require.Equal (which panics) and asserts the wrong
string; replace the require call inside the ErrorHandler with a testing.T method
(e.g., t.Errorf or t.Fatalf) to avoid panicking the test goroutine, and change
the asserted error text to match the ErrorCustomizer return value
(fiber.ErrInternalServerError.Error()) so ErrorHandler checks for "Internal
Server Error" instead of "[RECOVERED]: Hi, I'm an error!"; locate the closure
passed as ErrorHandler in Test_Recover and update the assertion and assertion
helper accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@middleware/recover/recover_test.go`:
- Around line 16-24: Test_Recover's ErrorHandler closure uses require.Equal
(which panics) and asserts the wrong string; replace the require call inside the
ErrorHandler with a testing.T method (e.g., t.Errorf or t.Fatalf) to avoid
panicking the test goroutine, and change the asserted error text to match the
ErrorCustomizer return value (fiber.ErrInternalServerError.Error()) so
ErrorHandler checks for "Internal Server Error" instead of "[RECOVERED]: Hi, I'm
an error!"; locate the closure passed as ErrorHandler in Test_Recover and update
the assertion and assertion helper accordingly.

ℹ️ Review info

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4011eec and 800f3db.

📒 Files selected for processing (2)
  • middleware/recover/config.go
  • middleware/recover/recover_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • middleware/recover/config.go

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
middleware/recover/recover_test.go (1)

18-19: ⚠️ Potential issue | 🟠 Major

Avoid require inside ErrorHandler closures.

Same issue as previously flagged: the linter disallows require.* in HTTP handlers. Use t.Errorf (or similar) inside the handler instead.

Based on learnings: In the Fiber codebase, the linter does not allow require assertions from within HTTP handlers (including net/http-style handlers).

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@middleware/recover/recover_test.go` around lines 18 - 19, The test's
ErrorHandler closure uses require.Equal inside the HTTP handler
(require.Equal(..., err.Error())), which the linter forbids; replace that
require call with t.Errorf (or t.Fatalf) to report the mismatch from the handler
instead of calling require, e.g., compare err.Error() to the expected string and
call t.Errorf with a descriptive message if it differs, leaving the rest of the
handler (return c.SendStatus(fiber.StatusTeapot)) unchanged so the test still
exercises the response path.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@middleware/recover/recover_test.go`:
- Around line 18-19: The test's ErrorHandler closure uses require.Equal inside
the HTTP handler (require.Equal(..., err.Error())), which the linter forbids;
replace that require call with t.Errorf (or t.Fatalf) to report the mismatch
from the handler instead of calling require, e.g., compare err.Error() to the
expected string and call t.Errorf with a descriptive message if it differs,
leaving the rest of the handler (return c.SendStatus(fiber.StatusTeapot))
unchanged so the test still exercises the response path.

ℹ️ Review info

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 800f3db and 83c52b3.

📒 Files selected for processing (3)
  • middleware/recover/config.go
  • middleware/recover/recover.go
  • middleware/recover/recover_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • middleware/recover/recover.go

@JonasDoe JonasDoe force-pushed the recover_with_error_creator branch from 5b7117e to 567bcd8 Compare February 24, 2026 13:57
@JonasDoe

JonasDoe commented Feb 24, 2026

Copy link
Copy Markdown
Contributor Author

@JonasDoe Please check the comments above. There's a few issues with the implementation.

  • The name ErrorCustomizer needs to be changed.
  • The docs/middleware/recover.md needs to be updated
  • The docs/whats_new.md needs to be updated

Hey @gaby , thank you for the fast reply. Some questions:

  • What's wrong with the name ErrorCustomizer? What would you prefer instead?
  • The docs/middleware/recover.md documention doesn't cover the recover configuration, so I didn't see the point is mentioning this particular feature there.
  • The docs/whats_new.md doesn't mention the recover middleware at all yet. I've added an entry - I hope that's what you had in miind.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

♻️ Duplicate comments (1)
middleware/recover/recover_test.go (1)

17-21: ⚠️ Potential issue | 🔴 Critical

require.Equal inside the ErrorHandler violates the linter rule.

The require assertion on line 18 is inside a fiber.Ctx-typed handler closure. The linter forbids require calls within HTTP handlers; use t.Errorf instead.

✅ Proposed fix
 	ErrorHandler: func(c fiber.Ctx, err error) error {
-		require.Equal(t, "[RECOVERED]: Hi, I'm an error!", err.Error())
+		if err == nil || err.Error() != "[RECOVERED]: Hi, I'm an error!" {
+			t.Errorf("expected %q, got %v", "[RECOVERED]: Hi, I'm an error!", err)
+		}
 		return c.SendStatus(fiber.StatusTeapot)
 	},

Based on learnings: "the linter does not allow require assertions from within HTTP handlers (including net/http-style handlers). Use t.Fatalf, t.Errorf, or similar testing.T methods for error handling inside handler functions instead."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@middleware/recover/recover_test.go` around lines 17 - 21, The test handler's
ErrorHandler closure uses require.Equal (inside the anonymous func(c fiber.Ctx,
err error) error) which violates the linter for HTTP handlers; replace the
require call with a testing.T method (e.g., t.Errorf or t.Fatalf) to report the
mismatch—check that err.Error() equals "[RECOVERED]: Hi, I'm an error!" using
t.Errorf/fatal and then return c.SendStatus(fiber.StatusTeapot) as before so the
assertion runs without using require inside ErrorHandler.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs/whats_new.md`:
- Around line 1591-1594: Fix the grammar in the Recover section: change the
possessive "it's `Config`" to "its `Config`" and change the article "Set a
`ErrorCustomizer`" to "Set an `ErrorCustomizer`"; update the sentence
referencing the Recover middleware, its `Config`, and the `ErrorCustomizer`
symbol accordingly.
- Around line 1591-1594: Update the Config documentation table in
docs/middleware/recover.md to include the missing ErrorCustomizer field
referenced by Recover and whats_new.md: add a row for ErrorCustomizer with Type
`func(fiber.Ctx, any) error`, Description "Customize the error returned from a
recovered panic.", and Default `defaultErrorCustomizer`; ensure it is placed
alongside Next, EnableStackTrace, and StackTraceHandler and uses the exact
symbol names ErrorCustomizer and defaultErrorCustomizer so the public API docs
match the implementation and whats_new.md mention.

---

Duplicate comments:
In `@middleware/recover/recover_test.go`:
- Around line 17-21: The test handler's ErrorHandler closure uses require.Equal
(inside the anonymous func(c fiber.Ctx, err error) error) which violates the
linter for HTTP handlers; replace the require call with a testing.T method
(e.g., t.Errorf or t.Fatalf) to report the mismatch—check that err.Error()
equals "[RECOVERED]: Hi, I'm an error!" using t.Errorf/fatal and then return
c.SendStatus(fiber.StatusTeapot) as before so the assertion runs without using
require inside ErrorHandler.

ℹ️ Review info

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 83c52b3 and 567bcd8.

📒 Files selected for processing (4)
  • docs/whats_new.md
  • middleware/recover/config.go
  • middleware/recover/recover.go
  • middleware/recover/recover_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • middleware/recover/config.go
  • middleware/recover/recover.go

Comment thread docs/whats_new.md

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Comment thread middleware/recover/recover_test.go Outdated
Comment thread middleware/recover/recover_test.go
Comment thread middleware/recover/config.go Outdated
Comment thread docs/middleware/recover.md
@gaby gaby changed the title 🔥Added ErrorCustomizer in recover middleware 🔥 feat: Add PanicHandler in recover middleware Feb 25, 2026
@gaby gaby requested a review from Copilot February 25, 2026 03:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Comment thread docs/middleware/recover.md Outdated
- Exposed DefaultPanicHandler since it might be useful for the users
@gaby gaby requested a review from Copilot February 25, 2026 13:10
@gaby

gaby commented Feb 25, 2026

Copy link
Copy Markdown
Member

/gemini review

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

Copy link
Copy Markdown
Contributor

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 introduces a PanicHandler to the recover middleware, enabling customization of errors generated from panics. The changes are well-implemented across the middleware's configuration, logic, tests, and documentation. My review includes suggestions to improve the clarity and consistency of the documentation's code examples and to enhance code maintainability by aligning struct literal field order with the struct definition.

Comment thread docs/middleware/recover.md Outdated
Comment thread middleware/recover/config.go

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Comment thread docs/middleware/recover.md
Comment thread middleware/recover/recover.go
Comment thread middleware/recover/config.go
@gaby

gaby commented Feb 25, 2026

Copy link
Copy Markdown
Member

@JonasDoe Few docs issues, and update the PR description. Other than that, it looks good.

@gaby

gaby commented Feb 25, 2026

Copy link
Copy Markdown
Member

@ReneWerner87 Do you remember why the docs are importing as recoverer ?

@ReneWerner87

Copy link
Copy Markdown
Member

@ReneWerner87 Do you remember why the docs are importing as recoverer ?

I don't remember,
but I can guess why:
so that there is no collision with the “recover” keyword in Golang.
image
https://go.dev/blog/defer-panic-and-recover

@ReneWerner87

Copy link
Copy Markdown
Member

https://handhikayp.medium.com/golang-101-6-the-reserved-keywords-in-go-1c8ef12d0fbf
image

@gaby gaby left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@ReneWerner87 ReneWerner87 merged commit 1c6dde5 into gofiber:main Feb 26, 2026
20 of 21 checks passed
@welcome

welcome Bot commented Feb 26, 2026

Copy link
Copy Markdown

Congrats on merging your first pull request! 🎉 We here at Fiber are proud of you! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord

@github-project-automation github-project-automation Bot moved this to Done in v3 Feb 26, 2026
@ReneWerner87 ReneWerner87 modified the milestones: v3, v3.1.0 Feb 27, 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.

📝 [Proposal]: Allow error customization in the recover middleware

4 participants