Skip to content

docs: clarify CBOR/MsgPack setup and fix tests#3584

Closed
ReneWerner87 wants to merge 5 commits into
mainfrom
test_copilot_auto_review
Closed

docs: clarify CBOR/MsgPack setup and fix tests#3584
ReneWerner87 wants to merge 5 commits into
mainfrom
test_copilot_auto_review

Conversation

@ReneWerner87
Copy link
Copy Markdown
Member

Description

Please provide a clear and concise description of the changes you've made and the problem they address. Include the purpose of the change, any relevant issues it solves, and the benefits it brings to the project. If this change introduces new features or adjustments, highlight them here.

Fixes # (issue)

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 review requested due to automatic review settings July 15, 2025 09:48
@ReneWerner87 ReneWerner87 requested a review from a team as a code owner July 15, 2025 09:48
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jul 15, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This change removes the default dependency on the external CBOR library and replaces the default CBOR marshal/unmarshal functions with stub functions that panic unless explicitly configured. Tests and documentation are updated to require explicit CBOR setup, and new documentation and examples are provided for CBOR configuration.

Changes

File(s) Change Summary
app.go Removed direct CBOR library import; replaced default CBOR encoder/decoder with unimplemented stubs; updated Config comments.
binder/cbor.go Added UnimplementedCborMarshal and UnimplementedCborUnmarshal stub functions that panic.
binder/cbor_test.go Added tests verifying stubs panic and contain correct messages.
bind_test.go, ctx_test.go, client/helper_test.go Updated app/test setup to explicitly configure CBOR encoder/decoder using external library.
docs/api/bind.md, docs/api/ctx.md Added notes about required CBOR setup with links to the setup guide.
docs/api/fiber.md Updated config field documentation for CBOR defaults and improved table formatting.
docs/guide/advance-format.md Expanded guide to include CBOR setup instructions and usage example.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant App
    participant Binder

    User->>App: Initialize with Config
    alt CBOR encoder/decoder not set
        App->>Binder: Call UnimplementedCborMarshal/Unmarshal
        Binder-->>App: Panic with setup instruction
    else CBOR encoder/decoder set
        App->>Binder: Call user-provided CBOR marshal/unmarshal
        Binder-->>App: Encode/Decode data
    end
Loading

Possibly related issues

Possibly related PRs

Suggested labels

📒 Documentation, 🧹 Updates, v3

Suggested reviewers

  • gaby
  • sixcolors
  • efectn

Poem

The Fiber rabbit hops with glee,
No CBOR by default, you see!
Now stubs will shout and tests will show,
"Set up your codecs before you go!"
Docs are clear, examples neat—
Explicit setup can't be beat.
🥕✨


📜 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 8503eef and 188858f.

📒 Files selected for processing (10)
  • app.go (2 hunks)
  • bind_test.go (4 hunks)
  • binder/cbor.go (1 hunks)
  • binder/cbor_test.go (1 hunks)
  • client/helper_test.go (2 hunks)
  • ctx_test.go (6 hunks)
  • docs/api/bind.md (1 hunks)
  • docs/api/ctx.md (1 hunks)
  • docs/api/fiber.md (2 hunks)
  • docs/guide/advance-format.md (2 hunks)
✨ 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
🪧 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
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.

Summary of Changes

Hello @ReneWerner87, 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 refines the handling of CBOR (Concise Binary Object Representation) within the Fiber framework by transitioning its implementation from an implicit default to an explicit opt-in mechanism. This change aims to provide greater clarity and control for users, ensuring they are aware of and actively configure their preferred CBOR serialization libraries. The core changes involve updating Fiber's configuration defaults, introducing panic-on-unimplemented functions for better user feedback, and thoroughly updating both the internal test suite and external documentation to reflect these new requirements.

Highlights

  • CBOR Default Behavior Change: Fiber no longer includes a default CBOR implementation. The CBOREncoder and CBORDecoder fields in fiber.Config now default to binder.UnimplementedCborMarshal and binder.UnimplementedCborUnmarshal respectively. These Unimplemented functions will panic if invoked without explicit configuration, providing clear guidance to the user.
  • Enhanced User Guidance: The newly introduced UnimplementedCborMarshal and UnimplementedCborUnmarshal functions panic with a specific message that directs users to the official documentation for instructions on how to properly set up CBOR encoding and decoding.
  • Comprehensive Documentation Updates: The documentation has been significantly updated to reflect the new CBOR setup requirements. This includes notes in the API reference for bind and ctx methods, updates to the fiber.Config table, and a detailed new section in the 'Advance Format' guide with code examples for configuring CBOR.
  • Test Suite Alignment: All relevant unit and benchmark tests across bind_test.go, client/helper_test.go, and ctx_test.go have been updated to explicitly configure CBOR encoders and decoders when creating a new Fiber application, ensuring the test suite aligns with the new explicit setup requirement.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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 issue 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 is currently in preview and 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 to provide feedback.

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 deleted the test_copilot_auto_review branch July 15, 2025 09:49
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

Clarifies the binary serialization setup for CBOR alongside MsgPack and updates code/tests to require explicit CBOR configuration.

  • Added CBOR section and setup instructions in the advanced formatting guide and linked it from API docs.
  • Changed default CBOR encoder/decoder to unimplemented stubs and removed the fxamacker/cbor import from core.
  • Updated tests and examples to explicitly configure CBOREncoder/CBORDecoder.

Reviewed Changes

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

Show a summary per file
File Description
docs/guide/advance-format.md Added CBOR setup instructions and updated frontmatter title
docs/api/fiber.md Fixed table formatting and updated default CBOREncoder/Decoder
docs/api/ctx.md Added a note linking to the CBOR guide
docs/api/bind.md Added a note linking to the CBOR guide
ctx_test.go Updated tests to supply CBOREncoder/CBORDecoder in Config
client/helper_test.go Updated test server setup to include CBOR encoder/decoder
binder/cbor.go Introduced unimplemented panic stubs for CBOR marshal/unmarshal
binder/cbor_test.go Added tests for the new unimplemented CBOR stubs
bind_test.go Added CBOR config to bind tests and benchmarks
app.go Switched default CBOR encoder/decoder to unimplemented stubs
Comments suppressed due to low confidence (3)

binder/cbor.go:27

  • Use the full uppercase acronym for CBOR in function names (e.g., rename to UnimplementedCBORMarshal) to stay consistent with the CBOREncoder/CBORDecoder type names.
func UnimplementedCborMarshal(_ any) ([]byte, error) {

binder/cbor.go:31

  • Use the full uppercase acronym for CBOR in function names (e.g., rename to UnimplementedCBORUnmarshal) to stay consistent with the CBOREncoder/CBORDecoder type names.
func UnimplementedCborUnmarshal(_ []byte, _ any) error {

docs/api/ctx.md:1900

  • [nitpick] For published docs linking, consider removing the .md extension so the link resolves correctly (e.g., ../guide/advance-format#cbor).
> **Note:** Before using any CBOR-related features, make sure to follow the [CBOR setup instructions](../guide/advance-format.md#cbor).

Comment thread ctx_test.go
func Test_Ctx_Accepts(t *testing.T) {
t.Parallel()
app := New()
app := New(Config{
Copy link

Copilot AI Jul 15, 2025

Choose a reason for hiding this comment

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

[nitpick] Several tests repeat Config setup with CBOREncoder/CBORDecoder; consider extracting a shared helper function to DRY up the test setup.

Copilot uses AI. Check for mistakes.
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 does a great job of making CBOR and MsgPack optional dependencies. This is a solid architectural improvement that reduces the default dependency footprint of the framework. The changes are consistent across the codebase, with updates to default configurations, tests, and documentation.

I've provided a few suggestions to improve test conciseness and fix some markdown formatting in the documentation for better readability. Overall, this is a well-executed change.

Comment thread binder/cbor_test.go
Comment on lines +93 to +131
func Test_UnimplementedCborMarshal_Panics(t *testing.T) {
t.Parallel()

require.Panics(t, func() {
_, _ = UnimplementedCborMarshal(struct{ Name string }{Name: "test"}) //nolint:errcheck // this is just a test to trigger the panic
})
}

func Test_UnimplementedCborUnmarshal_Panics(t *testing.T) {
t.Parallel()

require.Panics(t, func() {
var out any
_ = UnimplementedCborUnmarshal([]byte{0xa0}, &out) //nolint:errcheck // this is just a test to trigger the panic
})
}

func Test_UnimplementedCborMarshal_PanicMessage(t *testing.T) {
t.Parallel()

defer func() {
if r := recover(); r != nil {
require.Contains(t, r, "Must explicitly setup CBOR")
}
}()
_, _ = UnimplementedCborMarshal(struct{ Name string }{Name: "test"}) //nolint:errcheck // this is just a test to trigger the panic
}

func Test_UnimplementedCborUnmarshal_PanicMessage(t *testing.T) {
t.Parallel()

defer func() {
if r := recover(); r != nil {
require.Contains(t, r, "Must explicitly setup CBOR")
}
}()
var out any
_ = UnimplementedCborUnmarshal([]byte{0xa0}, &out) //nolint:errcheck // this is just a test to trigger the panic
}
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.

medium

These tests for panics and panic messages are a bit redundant. The _Panics and _PanicMessage tests for both Marshal and Unmarshal can be combined into a single test for each by using require.PanicsWithValue.

This will make the tests more concise and easier to maintain while also providing stronger assertions by checking for the exact panic message.

Suggested change
func Test_UnimplementedCborMarshal_Panics(t *testing.T) {
t.Parallel()
require.Panics(t, func() {
_, _ = UnimplementedCborMarshal(struct{ Name string }{Name: "test"}) //nolint:errcheck // this is just a test to trigger the panic
})
}
func Test_UnimplementedCborUnmarshal_Panics(t *testing.T) {
t.Parallel()
require.Panics(t, func() {
var out any
_ = UnimplementedCborUnmarshal([]byte{0xa0}, &out) //nolint:errcheck // this is just a test to trigger the panic
})
}
func Test_UnimplementedCborMarshal_PanicMessage(t *testing.T) {
t.Parallel()
defer func() {
if r := recover(); r != nil {
require.Contains(t, r, "Must explicitly setup CBOR")
}
}()
_, _ = UnimplementedCborMarshal(struct{ Name string }{Name: "test"}) //nolint:errcheck // this is just a test to trigger the panic
}
func Test_UnimplementedCborUnmarshal_PanicMessage(t *testing.T) {
t.Parallel()
defer func() {
if r := recover(); r != nil {
require.Contains(t, r, "Must explicitly setup CBOR")
}
}()
var out any
_ = UnimplementedCborUnmarshal([]byte{0xa0}, &out) //nolint:errcheck // this is just a test to trigger the panic
}
func Test_UnimplementedCborMarshal_Panics(t *testing.T) {
t.Parallel()
expectedPanicMsg := "Must explicitly setup CBOR, please check docs: https://docs.gofiber.io/next/guide/advance-format#cbor"
require.PanicsWithValue(t, expectedPanicMsg, func() {
_, _ = UnimplementedCborMarshal(struct{ Name string }{Name: "test"}) //nolint:errcheck // this is just a test to trigger the panic
})
}
func Test_UnimplementedCborUnmarshal_Panics(t *testing.T) {
t.Parallel()
expectedPanicMsg := "Must explicitly setup CBOR, please check docs: https://docs.gofiber.io/next/guide/advance-format#cbor"
require.PanicsWithValue(t, expectedPanicMsg, func() {
var out any
_ = UnimplementedCborUnmarshal([]byte{0xa0}, &out) //nolint:errcheck // this is just a test to trigger the panic
})
}

Comment thread docs/api/fiber.md
Comment on lines +45 to +46
| Property | Type | Description | Default |
|---------------------------------------------------------------------------------------|-----------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------|
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.

medium

The markdown table formatting for the Config fields seems to be misaligned, especially for the Default column. This can affect the readability of the raw markdown file. It's better to ensure the column separators are properly aligned with the content.

Suggested change
| Property | Type | Description | Default |
|---------------------------------------------------------------------------------------|-----------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------|
| Property | Type | Description | Default |
|---------------------------------------------------------------------------------------|-----------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------|

Comment thread docs/api/fiber.md
Comment on lines +106 to +107
| Property | Type | Description | Default |
|-------------------------------------------------------------------------|-------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------|
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.

medium

Similar to the previous table, the markdown formatting for this table is misaligned. Aligning the columns will improve the readability of the raw markdown.

Suggested change
| Property | Type | Description | Default |
|-------------------------------------------------------------------------|-------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------|
| Property | Type | Description | Default |
|-------------------------------------------------------------------------|-------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------|

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants