Skip to content

chore: Improve error messages in SaveFileToStorage#4173

Merged
ReneWerner87 merged 14 commits into
gofiber:mainfrom
pratikramteke:improve-error-messages
May 10, 2026
Merged

chore: Improve error messages in SaveFileToStorage#4173
ReneWerner87 merged 14 commits into
gofiber:mainfrom
pratikramteke:improve-error-messages

Conversation

@pratikramteke
Copy link
Copy Markdown
Contributor

Improve error messages in SaveFileToStorage by including filename and path.

This provides better debugging context when handling file upload errors.

@pratikramteke pratikramteke requested a review from a team as a code owner April 1, 2026 08:48
@ReneWerner87 ReneWerner87 added this to v3 Apr 1, 2026
@ReneWerner87 ReneWerner87 added this to the v3 milestone Apr 1, 2026
Copy link
Copy Markdown
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 enhances error reporting in the SaveFileToStorage function by including the filename and storage path in error messages. The reviewer recommends using the %q format verb instead of %s for these strings to ensure proper quoting and escaping of user-provided data, and highlights a potential information disclosure risk when including internal paths in errors.

Comment thread ctx.go Outdated
Comment thread ctx.go Outdated
Comment thread ctx.go Outdated
Comment thread ctx.go Outdated
Comment thread ctx.go Outdated
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 1, 2026

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

Added explicit nil check in DefaultCtx.SaveFileToStorage and four exported sentinel file errors; SaveFileToStorage now returns/wraps these errors with filenames (and destination path for store failures). Tests added for nil fileheader and BodyLimit filename propagation. No public signatures changed.

Changes

Cohort / File(s) Summary
SaveFileToStorage implementation
ctx.go
Added early return with ErrFileHeaderNil when fileheader is nil; replaced generic errors with exported ErrFileOpen, ErrFileRead, ErrFileStore; error messages now include fileheader.Filename and destination path for store errors.
File error declarations
error.go
Added four exported error variables: ErrFileHeaderNil, ErrFileOpen, ErrFileRead, ErrFileStore.
Tests for SaveFileToStorage
ctx_test.go
Added tests verifying nil *multipart.FileHeader returns ErrFileHeaderNil and that BodyLimit/read failure error messages include the multipart filename ("test-file.png").

Sequence Diagram(s)

(omitted)

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • ReneWerner87
  • efectn
  • sixcolors

Poem

🐰 I hop through bytes and name each file,

I catch the nil and pause a while,
I whisper filenames when things go wrong,
I tuck the path in tidy song,
a happy rabbit, error-proof and agile.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The description is minimal and lacks required sections from the template including Changes introduced checklist, Type of change selection, and Checklist items. Complete the PR description by filling out the template sections: select a Type of change (e.g., Enhancement, Code consistency), check relevant Checklist items, and describe any documentation or test updates.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: improving error messages in SaveFileToStorage with better context (filename and path).
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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.

pratikramteke and others added 3 commits April 1, 2026 14:26
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Comment thread ctx.go Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 1, 2026

Codecov Report

❌ Patch coverage is 77.77778% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.26%. Comparing base (0e5a233) to head (68dd7ce).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
ctx.go 77.77% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4173      +/-   ##
==========================================
+ Coverage   91.22%   91.26%   +0.03%     
==========================================
  Files         130      130              
  Lines       12756    12760       +4     
==========================================
+ Hits        11637    11645       +8     
+ Misses        706      704       -2     
+ Partials      413      411       -2     
Flag Coverage Δ
unittests 91.26% <77.77%> (+0.03%) ⬆️

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.

@ReneWerner87
Copy link
Copy Markdown
Member

@pratikramteke pls check the hints

@gaby gaby changed the title improve error messages in SaveFileToStorage chore: Improve error messages in SaveFileToStorage Apr 2, 2026
@gaby
Copy link
Copy Markdown
Member

gaby commented Apr 2, 2026

@pratikramteke The error needs to be defined in error.go. Then returned that predefined error.

@efectn
Copy link
Copy Markdown
Member

efectn commented Apr 3, 2026

Please check unit tests and lintci errors

Comment thread ctx.go Outdated
Copy link
Copy Markdown
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 aims to improve debugging for SaveFileToStorage failures by adding file-related sentinel errors and including more context (e.g., filename/path) in returned errors.

Changes:

  • Added new exported file-related sentinel errors in error.go.
  • Updated DefaultCtx.SaveFileToStorage to return those sentinel errors and to include filename/path details in error messages.
  • Added tests covering nil file header handling and verifying that error messages include the filename.

Reviewed changes

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

File Description
error.go Adds exported sentinel errors for file operations used by SaveFileToStorage.
ctx.go Updates SaveFileToStorage to use new sentinel errors and enrich error messages.
ctx_test.go Adds tests for nil file headers and filename presence in error messages.

Comment thread ctx.go Outdated
Comment thread ctx.go
Comment thread ctx.go Outdated
Comment thread ctx.go
Comment thread ctx_test.go
Comment thread ctx.go
Comment thread ctx.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@gaby
Copy link
Copy Markdown
Member

gaby commented May 9, 2026

@pratikramteke Can you fix the review issues? Thanks

ReneWerner87 and others added 5 commits May 10, 2026 14:22
Address review feedback on PR gofiber#4173:
- Use %w for all underlying errors in SaveFileToStorage so callers can
  errors.Is/As fasthttp.ErrBodyTooLarge and storage-specific errors;
  also satisfies errorlint.
- Restore Test_Ctx_SaveFileToStorage_LimitExceeded(_UnknownSize) which
  rely on errors.Is(err, fasthttp.ErrBodyTooLarge).
- Drop the misplaced "test-path" assertion from
  Test_Ctx_SaveFileToStorage_ErrorMessageContainsFilename: the BodyLimit
  branch intentionally does not include path. Add ErrorIs assertions on
  the new sentinels instead.
- Add Test_Ctx_SaveFileToStorage_StoreErrorIncludesPath that triggers
  the storage failure branch and asserts both filename and path appear
  in the error.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
SaveFile had the same nil-panic vector as SaveFileToStorage:
fasthttp.SaveMultipartFile -> fh.Open() panics on nil. Return
ErrFileHeaderNil for consistency with SaveFileToStorage and add
Test_Ctx_SaveFile_NilFileHeader.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- Add Test_Ctx_SaveFileToStorage_DefaultBodyLimitFallback to cover the
  defensive maxUploadSize <= 0 branch (raises SaveFileToStorage
  coverage from 86.4% to 90.9%).
- Drop unused method receiver names on failingStorage helpers to
  satisfy revive (unused-receiver).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@ReneWerner87 ReneWerner87 merged commit fb74afc into gofiber:main May 10, 2026
17 of 18 checks passed
@welcome
Copy link
Copy Markdown

welcome Bot commented May 10, 2026

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 May 10, 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.

5 participants