Skip to content

chore: Add test coverage for multipart BodyLimit error handling - #4237

Merged
ReneWerner87 merged 3 commits into
mainfrom
copilot/fix-multipart-form-error-handling
May 7, 2026
Merged

ReneWerner87 merged 3 commits into
mainfrom
copilot/fix-multipart-form-error-handling

Conversation

Copilot AI commented Apr 25, 2026

Copy link
Copy Markdown
Contributor

Description

Oversized multipart uploads were reported as bypassing custom ErrorHandler responses and surfacing as a generic client-side network error instead of a 413 response. This PR adds regression coverage for that path so multipart requests exceeding BodyLimit are verified to return the same custom error response shape as other oversized requests.

  • What changed

    • Added an integration test for oversized multipart/form-data requests handled through a custom ErrorHandler
    • Asserted the response status remains 413 Request Entity Too Large
    • Asserted the custom handler response body and content type are preserved for multipart uploads
  • Regression coverage

    • Exercises the server-level oversized body path with a real multipart payload
    • Verifies the error is translated into *fiber.Error and serialized by the app’s custom error handler, rather than failing as a transport-level "error" on the client
  • Example

    app := fiber.New(fiber.Config{
        BodyLimit: 128,
        ErrorHandler: func(c fiber.Ctx, err error) error {
            code := fiber.StatusInternalServerError
            var fiberErr *fiber.Error
            if errors.As(err, &fiberErr) {
                code = fiberErr.Code
            }
    
            return c.Status(code).JSON(fiber.Map{
                "code":    code,
                "message": err.Error(),
            })
        },
    })

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: Detail the updates made to the documentation and links to the changed files.
  • Changelog/What's New: Include a summary of the additions for the upcoming release notes.
  • Migration Guide: If necessary, provide a guide or steps for users to migrate their existing code to accommodate these changes.
  • API Alignment with Express: Explain how the changes align with the Express API.
  • API Longevity: Discuss the steps taken to ensure that the new or updated APIs are consistent and not prone to breaking changes.
  • Examples: Provide examples demonstrating the new features or changes in action.

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • Enhancement (improvement to existing features and functionality)
  • Documentation update (changes to documentation)
  • Performance improvement (non-breaking change which improves efficiency)
  • 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.

Commit formatting

Please use emojis in commit messages for an easy way to identify the purpose or intention of a commit. Check out the emoji cheatsheet here: CONTRIBUTING.md

Copilot AI linked an issue Apr 25, 2026 that may be closed by this pull request
3 tasks
Copilot AI changed the title [WIP] Fix error handling for multipart forms exceeding BodyLimit 🐛 bug: cover multipart BodyLimit error handling with a regression test Apr 25, 2026
Copilot AI requested a review from gaby April 25, 2026 21:44
Copilot finished work on behalf of gaby April 25, 2026 21:44
@ReneWerner87 ReneWerner87 added this to v3 Apr 25, 2026
@ReneWerner87 ReneWerner87 added this to the v3 milestone Apr 25, 2026
@codecov

codecov Bot commented Apr 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.25%. Comparing base (7dc9e8e) to head (cb6cf0c).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4237   +/-   ##
=======================================
  Coverage   91.25%   91.25%           
=======================================
  Files         127      127           
  Lines       12556    12556           
=======================================
  Hits        11458    11458           
  Misses        687      687           
  Partials      411      411           
Flag Coverage Δ
unittests 91.25% <ø> (ø)

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.

@gaby gaby changed the title 🐛 bug: cover multipart BodyLimit error handling with a regression test chore: Add test coverage for multipart BodyLimit error handling Apr 26, 2026
@gaby
gaby marked this pull request as ready for review May 5, 2026 03:54
Copilot AI review requested due to automatic review settings May 5, 2026 03:54
@gaby
gaby requested a review from a team as a code owner May 5, 2026 03:54
@gaby
gaby requested review from ReneWerner87, efectn and sixcolors May 5, 2026 03:54

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 a regression integration test around Fiber’s server-level BodyLimit handling so oversized multipart/form-data requests are verified to flow through a custom ErrorHandler the same way other oversized requests already do.

Changes:

  • Added a new integration test covering oversized multipart uploads with a custom JSON ErrorHandler.
  • Verifies the response still returns HTTP 413 for multipart requests that exceed BodyLimit.
  • Verifies the custom handler’s JSON body and content type are preserved on that failure path.

@github-actions github-actions 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.

⚠️ 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: cb6cf0c Previous: 7dc9e8e Ratio
BenchmarkDecoderedirectionMsgs (github.com/gofiber/fiber/v3) 20.21 ns/op 49.47 MB/s 0 B/op 0 allocs/op 8.347 ns/op 119.81 MB/s 0 B/op 0 allocs/op 2.42
BenchmarkDecoderedirectionMsgs (github.com/gofiber/fiber/v3) - ns/op 20.21 ns/op 8.347 ns/op 2.42

This comment was automatically generated by workflow using github-action-benchmark.

@ReneWerner87
ReneWerner87 merged commit fd45473 into main May 7, 2026
24 of 25 checks passed
@github-project-automation github-project-automation Bot moved this to Done in v3 May 7, 2026
@ReneWerner87
ReneWerner87 deleted the copilot/fix-multipart-form-error-handling branch May 7, 2026 06:08
@ReneWerner87 ReneWerner87 modified the milestones: v3, v3.3.0 May 22, 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.

🐛 [Bug]: 413 not returned back to firefox

4 participants