Skip to content

🔥 Feature: Enhance CheckConstraint method for improved error handling #3356

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
merged 24 commits into from
Apr 1, 2025

Conversation

JIeJaitt
Copy link
Contributor

@JIeJaitt JIeJaitt commented Mar 18, 2025

Description

Functions can now override custom constraint configurations and gofiber's built-in constraint configurations

close #3352

Copy link
Contributor

coderabbitai bot commented Mar 18, 2025

Walkthrough

The changes update the CheckConstraint method to improve validation by prioritizing custom constraints and introducing explicit error checks during data conversions for integers, booleans, floats, UUIDs, and dates. The method now validates that the necessary data is present before proceeding and returns a simplified boolean result. Additionally, a new regex-based test case for numeric parameters has been added in the test file, and the routing documentation now includes a note clarifying that custom constraints override built-in ones when sharing the same name.

Changes

File Change Summary
path.go Modified the CheckConstraint method to check for custom constraints first, validate required data, and handle conversion errors (int, bool, float, UUID, date).
path_testcases_test.go Introduced a new test case with the pattern /api/v1/:param<regex(\d+)> to verify that numeric URL segments match correctly.
docs/guide/routing.md Added a caution note clarifying that custom constraints can override built-in constraints if they share the same name.

Sequence Diagram(s)

sequenceDiagram
    participant Caller as Caller
    participant Constraint as Constraint

    Caller->>Constraint: CheckConstraint(param)
    Constraint->>Constraint: Check for custom constraint override
    alt Custom constraint exists
        Constraint-->>Caller: return true
    else No custom constraint found
        Constraint->>Constraint: Validate required data
        Constraint->>Constraint: Convert param to int, bool, float, UUID, date
        alt Conversion error occurs
            Constraint-->>Caller: return false
        else All conversions succeed
            Constraint-->>Caller: return true
        end
    end
Loading

Poem

I'm a rabbit with hops so bright,
Coding constraints in day and night,
Custom rules lead my little flight,
Data conversions checked just right,
Test cases dance and docs take flight,
Bouncing through code with pure delight! 🐇


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b2debdb and 6e399dc.

📒 Files selected for processing (1)
  • docs/guide/routing.md (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • docs/guide/routing.md

Note

🎁 Summarized by CodeRabbit Free

Your organization has reached its limit of developer seats under the Pro Plan. For new users, CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please add seats to your subscription by visiting https://app.coderabbit.ai/login.If you believe this is a mistake and have available seats, please assign one to the pull request author through the subscription management page using the link above.

🪧 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 plan to trigger planning for file edits and PR creation.
  • @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.

@ReneWerner87 ReneWerner87 added this to v3 Mar 18, 2025
@ReneWerner87 ReneWerner87 added this to the v3 milestone Mar 18, 2025
@JIeJaitt JIeJaitt marked this pull request as ready for review March 18, 2025 09:45
@ReneWerner87 ReneWerner87 requested a review from efectn March 18, 2025 09:45
@JIeJaitt JIeJaitt removed the request for review from efectn March 18, 2025 09:45
@JIeJaitt JIeJaitt requested a review from a team as a code owner March 18, 2025 09:45
@JIeJaitt JIeJaitt requested review from gaby, sixcolors, ReneWerner87 and efectn and removed request for a team March 18, 2025 09:45
@ReneWerner87
Copy link
Member

ReneWerner87 commented Mar 18, 2025

cool interesting

@efectn efectn moved this to In Progress in v3 Mar 18, 2025
@ReneWerner87
Copy link
Member

@JIeJaitt pls check the tests
image

Copy link

codecov bot commented Mar 19, 2025

Codecov Report

Attention: Patch coverage is 85.71429% with 3 lines in your changes missing coverage. Please review.

Project coverage is 83.93%. Comparing base (bb12633) to head (6e399dc).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
path.go 85.71% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3356      +/-   ##
==========================================
- Coverage   83.94%   83.93%   -0.02%     
==========================================
  Files         119      119              
  Lines       11893    11904      +11     
==========================================
+ Hits         9984     9992       +8     
- Misses       1482     1484       +2     
- Partials      427      428       +1     
Flag Coverage Δ
unittests 83.93% <85.71%> (-0.02%) ⬇️

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.

@JIeJaitt JIeJaitt force-pushed the feature/improve-check-constraint branch from 0e02256 to d92e7f6 Compare March 27, 2025 07:33
…t/fiber into feature/improve-check-constraint
@ReneWerner87 ReneWerner87 merged commit c5c7f86 into gofiber:main Apr 1, 2025
17 of 18 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in v3 Apr 1, 2025
efectn pushed a commit to ckoch786/fiber that referenced this pull request May 15, 2025
…gofiber#3356)

* 🔥 Feature: Enhance CheckConstraint method for improved error handling

* Revert "🔥 Feature: Enhance CheckConstraint method for improved error handling"

This reverts commit 68e8777.

* Reapply "🔥 Feature: Enhance CheckConstraint method for improved error handling"

This reverts commit 9e6c8e6.

* 🚨 Test: Add comprehensive tests for CheckConstraint method with various constraint scenarios

* 🩹 Fix: lint error

* 🩹 Fix: Update CheckConstraint method to return true for noConstraint and improve error handling

* ♻️ Refactor: Remove unused CheckConstraint test cases and reorganize benchmark test cases for clarity

* ♻️ Refactor: Remove outdated test cases from path_testcases_test.go and clean up CheckConstraint method in path.go

* 📚 Doc: Update custom constraints section to clarify overriding behavior

* 🔥 Feature: Enhance CheckConstraint method for improved error handling

* Revert "🔥 Feature: Enhance CheckConstraint method for improved error handling"

This reverts commit 68e8777.

* Reapply "🔥 Feature: Enhance CheckConstraint method for improved error handling"

This reverts commit 9e6c8e6.

* 🚨 Test: Add comprehensive tests for CheckConstraint method with various constraint scenarios

* 🩹 Fix: lint error

* 🩹 Fix: Update CheckConstraint method to return true for noConstraint and improve error handling

* ♻️ Refactor: Remove unused CheckConstraint test cases and reorganize benchmark test cases for clarity

* ♻️ Refactor: Remove outdated test cases from path_testcases_test.go and clean up CheckConstraint method in path.go

* 📚 Doc: Update custom constraints section to clarify overriding behavior

* 📚 Doc: Add caution note about custom constraints overriding built-in constraints in routing guide

---------

Co-authored-by: Juan Calderon-Perez <[email protected]>
Co-authored-by: RW <[email protected]>
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.

📝 [Proposal]: ability to override CustomConstraint
4 participants