Skip to content

🔥 feat: Add support for NewErrorf #3463

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

gaby
Copy link
Member

@gaby gaby commented May 21, 2025

Summary

  • Add support for variadic parameters in NewError via new function called: NewErrorf

Related to #3455

@gaby gaby added the codex label May 21, 2025 — with ChatGPT Connector
Copy link
Contributor

coderabbitai bot commented May 21, 2025

Walkthrough

A new function, NewErrorf, was introduced to enable flexible and formatted error message creation with variadic arguments. Comprehensive tests and documentation were added to describe and verify its behavior. The changelog now lists this addition among other recent updates.

Changes

File(s) Change Summary
app.go Added NewErrorf function for formatted error creation with variadic arguments.
app_test.go Introduced Test_NewErrorf_Format to validate NewErrorf with various input scenarios.
docs/api/fiber.md Documented NewErrorf usage, signature, and example in the API reference.
docs/whats_new.md Updated changelog to include the new NewErrorf method for formatted errors.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant FiberApp

    Caller->>FiberApp: NewErrorf(code, ...message)
    alt No message arguments
        FiberApp-->>Caller: Error{code, default status message}
    else One argument
        FiberApp-->>Caller: Error{code, stringified argument}
    else Multiple arguments
        alt First argument is string
            FiberApp-->>Caller: Error{code, formatted message}
        else
            FiberApp-->>Caller: Error{code, stringified first argument}
        end
    end
Loading

Suggested reviewers

  • ReneWerner87
  • sixcolors

Poem

🐇
A new error hops into view,
With formats and codes, it’s shiny and new.
From strings to nil, it handles all,
In tests and docs, it stands tall.
So here’s to errors, now dressed up fine—
With NewErrorf, your bugs will align!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ec6e7fe and b176f4a.

📒 Files selected for processing (1)
  • docs/whats_new.md (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • docs/whats_new.md
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: unit (1.24.x, macos-13)
  • GitHub Check: unit (1.24.x, windows-latest)
  • GitHub Check: unit (1.23.x, windows-latest)
  • GitHub Check: repeated
  • GitHub Check: Compare

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codecov bot commented May 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.42%. Comparing base (d756ec1) to head (b176f4a).
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3463      +/-   ##
==========================================
+ Coverage   84.35%   84.42%   +0.07%     
==========================================
  Files         120      120              
  Lines       12190    12213      +23     
==========================================
+ Hits        10283    10311      +28     
+ Misses       1477     1473       -4     
+ Partials      430      429       -1     
Flag Coverage Δ
unittests 84.42% <100.00%> (+0.07%) ⬆️

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 added this to v3 May 21, 2025
@gaby gaby added this to the v3 milestone May 21, 2025
@gaby gaby moved this to In Progress in v3 May 21, 2025
@gaby gaby changed the title Add variadic message support to NewError 🔥 feat: Add variadic message support to NewError May 21, 2025
@gaby gaby requested a review from Copilot May 21, 2025 03:36
@gaby gaby marked this pull request as ready for review May 21, 2025 03:36
@gaby gaby requested a review from a team as a code owner May 21, 2025 03:36
@gaby gaby requested review from sixcolors, ReneWerner87 and efectn May 21, 2025 03:36
Copy link
Contributor

@Copilot 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

Adds support for variadic arguments in NewError for flexible message formatting, updates usage sites to the new signature, refreshes related documentation, and expands test coverage for formatting behaviors.

  • Extend NewError to accept ...any and format messages via fmt.Sprintf
  • Update SendFile error handling and documentation examples to the new API
  • Add comprehensive tests in Test_NewError_Format

Reviewed Changes

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

Show a summary per file
File Description
docs/guide/error-handling.md Updated example to use variadic format arguments
docs/api/fiber.md Changed NewError signature to ...any and example
ctx.go Replaced fmt.Sprintf call with direct NewError use
app.go Implemented variadic overload logic in NewError
app_test.go Added tests for various NewError formatting scenarios
Comments suppressed due to low confidence (1)

app_test.go:1313

  • [nitpick] It may be helpful to add a test case for a format string with no matching parameters (e.g., "missing %s" without args) to confirm NewError's behavior in that edge case.
// go test -run Test_NewError_Format

Co-authored-by: Copilot <[email protected]>
github-actions[bot]

This comment was marked as outdated.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e3663d5 and 3b2f8c3.

📒 Files selected for processing (1)
  • app.go (1 hunks)
🧰 Additional context used
🪛 GitHub Check: unit (1.24.x, ubuntu-latest)
app.go

[failure] 902-902:
undefined: msg


[failure] 898-898:
undefined: msg


[failure] 894-894:
undefined: msg

🪛 GitHub Check: unit (1.24.x, macos-latest)
app.go

[failure] 902-902:
undefined: msg


[failure] 898-898:
undefined: msg


[failure] 894-894:
undefined: msg

🪛 GitHub Check: unit (1.23.x, macos-latest)
app.go

[failure] 902-902:
undefined: msg


[failure] 898-898:
undefined: msg


[failure] 894-894:
undefined: msg


[failure] 902-902:
undefined: msg


[failure] 898-898:
undefined: msg


[failure] 894-894:
undefined: msg

🪛 GitHub Check: unit (1.23.x, ubuntu-latest)
app.go

[failure] 902-902:
undefined: msg


[failure] 898-898:
undefined: msg


[failure] 894-894:
undefined: msg


[failure] 902-902:
undefined: msg


[failure] 898-898:
undefined: msg


[failure] 894-894:
undefined: msg

🪛 GitHub Check: lint
app.go

[failure] 902-902:
undefined: msg (typecheck)


[failure] 898-898:
undefined: msg


[failure] 894-894:
undefined: msg

🪛 GitHub Check: govulncheck-check
app.go

[failure] 902-902:
undefined: msg


[failure] 898-898:
undefined: msg


[failure] 894-894:
undefined: msg

🪛 GitHub Actions: golangci-lint
app.go

[error] 894-894: golangci-lint error: undefined variable 'msg'

🪛 GitHub Actions: Run govulncheck
app.go

[error] 894-894: Undefined identifier 'msg' at line 894, column 3.

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Compare
  • GitHub Check: Analyse
  • GitHub Check: repeated

@ReneWerner87
Copy link
Member

@gaby can we improve the performance ?
or should we leave this in the case as it is an error case

@gaby gaby changed the title 🔥 feat: Add variadic message support to NewError 🔥 feat: Add support for NewErrorf May 26, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
docs/whats_new.md (2)

3-3: Grammar: Title apostrophe
Consider updating the title to "🆕 What's New in v3" (adding the apostrophe) for correct English.


69-69: Include a link to the NewErrorf API docs and usage example
The new NewErrorf entry would benefit from a direct hyperlink to its detailed API documentation (e.g., docs/api/fiber.md#NewErrorf) and a brief code snippet showing its signature and usage. This aligns with other method entries and improves discoverability.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bf21de8 and ec6e7fe.

📒 Files selected for processing (2)
  • docs/api/fiber.md (1 hunks)
  • docs/whats_new.md (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • docs/api/fiber.md
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: unit (1.23.x, macos-13)
  • GitHub Check: unit (1.24.x, windows-latest)
  • GitHub Check: unit (1.23.x, macos-latest)
  • GitHub Check: unit (1.23.x, windows-latest)
  • GitHub Check: repeated
  • GitHub Check: Compare

@ReneWerner87 ReneWerner87 merged commit 23fb15f into main May 27, 2025
17 of 18 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in v3 May 27, 2025
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