Skip to content
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

Proposal: Remove Must and Should when binding structs #3178

Closed
wants to merge 6 commits into from

Conversation

ItsMeSamey
Copy link
Contributor

Bugs Fixed

Fixes issue described in #3171

Changes introduced

Removed Must, Should and related code and tests

ItsMeSamey and others added 6 commits October 18, 2024 02:16
if err is nil err.Error() panics
(eg. c.Bind().Must().JSON(...) successfully binds but panics
make sure returnErr works with nil error
as in majority of cases we expect err to be nil, this should provide better short-cutting
@ItsMeSamey ItsMeSamey marked this pull request as ready for review October 23, 2024 17:45
@ItsMeSamey ItsMeSamey requested a review from a team as a code owner October 23, 2024 17:45
@ItsMeSamey ItsMeSamey requested review from gaby, sixcolors, ReneWerner87 and efectn and removed request for a team October 23, 2024 17:45
Copy link
Contributor

coderabbitai bot commented Oct 23, 2024

Walkthrough

The pull request implements significant changes to the Bind struct within the fiber package by removing the should field and its associated methods, simplifying the error handling process. The bind_test.go file is updated to remove the Test_Bind_Must function and introduce a custom binder for testing various data types. Additionally, modifications are made to the DefaultCtx struct in ctx.go, specifically in the initialization of the Bind struct and the documentation of the Reset method.

Changes

File Change Summary
bind.go Removed should field and methods (Should, Must, returnErr) from Bind struct; updated binder methods to return errors directly.
bind_test.go Removed Test_Bind_Must; added customBinder for testing; updated test cases to use the custom binder.
ctx.go Removed should: true from Bind initialization in DefaultCtx; added comment to Reset method for clarity.

Possibly related PRs

Suggested labels

🧹 Updates, v3

Suggested reviewers

  • sixcolors
  • ReneWerner87
  • gaby

🐰 In the meadow, changes bloom,
The should field has met its doom.
With tests refined and logic clear,
Binding errors now bring cheer!
A custom way to bind and test,
In Fiber's heart, we do our best! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 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.

@ItsMeSamey
Copy link
Contributor Author

@efectn please review whenever possible

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

🧹 Outside diff range and nitpick comments (1)
bind.go (1)

43-43: Update method documentation

The comment above the Custom method still mentions "Should/Must is still valid for Custom binders" which is no longer accurate since this functionality has been removed.

-// NOTE: Should/Must is still valid for Custom binders.
+// Binds data using a custom binder registered with the Fiber instance.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 298975a and dde4c81.

📒 Files selected for processing (3)
  • bind.go (11 hunks)
  • bind_test.go (0 hunks)
  • ctx.go (0 hunks)
💤 Files with no reviewable changes (2)
  • bind_test.go
  • ctx.go
🧰 Additional context used
🔇 Additional comments (8)
bind.go (8)

22-22: LGTM: Simplified Bind struct

The removal of the should field aligns with the PR objective to remove Must/Should functionality, resulting in a cleaner and simpler struct definition.


Line range hint 52-56: LGTM: Clean error handling implementation

The error handling is now more straightforward with direct returns, while maintaining proper struct validation.


61-65: LGTM: Consistent error handling

The implementation follows the same pattern as other binding methods, maintaining consistency across the codebase.


Line range hint 71-75: LGTM: Proper error handling with validation

The implementation correctly handles errors from the cookie binder and maintains struct validation.


Line range hint 80-84: LGTM: Consistent implementation across all binding methods

All binding methods (Query, JSON, XML, Form, URI) follow the same pattern of direct error handling and validation, maintaining consistency and simplifying the codebase.

Also applies to: 89-93, 98-102, 107-111, 116-120


Line range hint 125-129: LGTM: Proper multipart form handling

The implementation correctly handles multipart form binding with appropriate error handling and validation.


147-147: LGTM: Proper custom binder handling

The implementation correctly handles custom binder parsing with direct error returns, consistent with the new error handling approach.


Line range hint 1-165: Verify complete removal of Must/Should functionality

Let's verify that all references to Must/Should have been properly removed from the codebase.

@ReneWerner87
Copy link
Member

@ItsMeSamey we have decided to keep the feature to fill the response automatically

thank you for bringing this topic to our attention

we can keep your other PR and expand it if necessary
the real problem is that we have adopted GIN's naming for this feature and this is misleading
because MUST is usually used in the context of panics

here, however, it should only be decided whether the response may be prefilled with the error

so we want to rename this functionality and document it better, and you can help us with this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants