8000 fix: obscur error message when trying to use experimental features while the service is not configured for by gfyrag · Pull Request #964 · formancehq/ledger · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: obscur error message when trying to use experimental features while the service is not configured for #964

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 1 commit into from
Jun 13, 2025

Conversation

gfyrag
Copy link
Contributor
@gfyrag gfyrag commented Jun 13, 2025

No description provided.

@gfyrag gfyrag requested a review from a team as a code owner June 13, 2025 14:48
Copy link
coderabbitai bot 8000 commented Jun 13, 2025

Walkthrough

The error handling in the ledger creation API was updated to treat the system.ErrExperimentalFeaturesDisabled error as a validation error, returning a 400 Bad Request. The end-to-end tests for ledger creation were refactored to clearly distinguish behaviors with and without experimental features enabled, expanding test coverage for both scenarios.

Changes

File(s) Change Summary
internal/api/v2/controllers_ledgers_create.go Expanded error handling in createLedger to treat ErrExperimentalFeaturesDisabled as validation.
test/e2e/api_ledgers_create_test.go Refactored and extended tests to differentiate behaviors with/without experimental features.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant API
    participant System

    Client->>API: POST /ledgers (createLedger)
    API->>System: Validate ledger config
    alt Invalid config or experimental features disabled
        System-->>API: Return validation error
        API-->>Client: 400 Bad Request (ValidationError)
    else Valid config
        System-->>API: Success
        API-->>Client: 201 Created
    end
Loading

Suggested reviewers

  • Dav-14
  • flemzord

Poem

In the warren where features bloom and hide,
A ledger’s fate now turns with the experimental tide.
With tests that split the burrow in two,
Old errors and new are caught in review.
Rabbits rejoice as coverage expands—
Hopping through code with diligent hands! 🐇

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Commit Unit Tests in branch fix/experimental-features-bad-status-code
  • Post Copyable Unit Tests in Comment

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 auto-generate unit tests to generate unit tests for 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.

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

🧹 Nitpick comments (2)
test/e2e/api_ledgers_create_test.go (2)

135-136: Empty It block – assertions belong inside the spec

The It("should fail", func() {}) contains no expectations; failures are asserted in JustBeforeEach.
This passes linting but obscures intent. Move the expectations into the It or convert the hook into an It-block for clarity.


30-80: High duplication between the two contexts

Both “without experimental features” and “with experimental features” spin up almost identical test-server scaffolding. Consider parameterising the feature flag and using DescribeTable/BeforeAll to cut repetition and speed up suite execution.

Also applies to: 71-110

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 23b6baf and bdab4f6.

📒 Files selected for processing (2)
  • internal/api/v2/controllers_ledgers_create.go (1 hunks)
  • test/e2e/api_ledgers_create_test.go (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
internal/api/v2/controllers_ledgers_create.go (1)
internal/controller/system/errors.go (1)
  • ErrExperimentalFeaturesDisabled (11-11)
test/e2e/api_ledgers_create_test.go (5)
pkg/client/models/operations/v2createledger.go (1)
  • V2CreateLedgerRequest (9-13)
pkg/features/features.go (2)
  • MinimalFeatureSet (35-41)
  • FeatureMovesHistoryPostCommitEffectiveVolumes (18-18)
pkg/client/models/components/v2errorsenum.go (2)
  • V2ErrorsEnumValidation (15-15)
  • V2ErrorsEnumLedgerAlreadyExists (29-29)
pkg/testserver/server.go (1)
  • ExperimentalFeaturesInstrumentation (29-34)
pkg/client/models/operations/v2getledger.go (2)
  • V2GetLedgerRequest (9-12)
  • V2GetLedgerResponse (21-25)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Dirty
  • GitHub Check: Tests
🔇 Additional comments (1)
internal/api/v2/controllers_ledgers_create.go (1)

34-40: ErrExperimentalFeaturesDisabled correctly mapped to 400, but double-check semantics

Treating a “feature disabled by config” situation as a validation error (400) is consistent with the existing mapping, yet it can be argued that this is more an authorization / capability issue (often 403).
Please ensure that:

  1. API docs & OpenAPI definition are updated accor 8000 dingly.
  2. Other endpoints that can raise the same error are also aligned, otherwise clients will face inconsistent status codes.

Comment on lines +128 to +134
JustBeforeEach(func(specContext SpecContext) {
_, err := Wait(specContext, DeferClient(testServer)).Ledger.V2.CreateLedger(ctx, operations.V2CreateLedgerRequest{
Ledger: createLedgerRequest.Ledger,
})
Expect(err).NotTo(BeNil())
Expect(err).To(HaveErrorCode(string(components.V2ErrorsEnumLedgerAlreadyExists)))
})
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Shadowed err hides outer variable

:= creates a new err, so the outer-scoped err checked by the (empty) It block is never updated.
Replace the short declaration with assignment to keep a single source of truth:

-    _, err := Wait(specContext, DeferClient(testServer)).Ledger.V2.CreateLedger(ctx, operations.V2CreateLedgerRequest{
+    _, err = Wait(specContext, DeferClient(testServer)).Ledger.V2.CreateLedger(ctx, operations.V2CreateLedgerRequest{
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
JustBeforeEach(func(specContext SpecContext) {
_, err := Wait(specContext, DeferClient(testServer)).Ledger.V2.CreateLedger(ctx, operations.V2CreateLedgerRequest{
Ledger: createLedgerRequest.Ledger,
})
Expect(err).NotTo(BeNil())
Expect(err).To(HaveErrorCode(string(components.V2ErrorsEnumLedgerAlreadyExists)))
})
JustBeforeEach(func(specContext SpecContext) {
_, err = Wait(specContext, DeferClient(testServer)).Ledger.V2.CreateLedger(ctx, operations.V2CreateLedgerRequest{
Ledger: createLedgerRequest.Ledger,
})
Expect(err).NotTo(BeNil())
Expect(err).To(HaveErrorCode(string(components.V2ErrorsEnumLedgerAlreadyExists)))
})
🤖 Prompt for AI Agents
In test/e2e/api_ledgers_create_test.go around lines 128 to 134, the variable err
is redeclared using := inside the JustBeforeEach block, which shadows the outer
err variable and prevents it from being updated. Replace the short variable
declaration := with a simple assignment = to update the existing err variable
instead of creating a new one, ensuring the outer err reflects the result of the
CreateLedger call.

Copy link
codecov bot commented Jun 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.78%. Comparing base (23b6baf) to head (bdab4f6).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #964      +/-   ##
==========================================
- Coverage   82.82%   82.78%   -0.04%     
==========================================
  Files         142      142              
  Lines        8028     8028              
==========================================
- Hits         6649     6646       -3     
- Misses       1054     1056       +2     
- Partials      325      326       +1     

☔ 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@gfyrag gfyrag added this pull request to the merge queue Jun 13, 2025
Merged via the queue into main with commit 66b6edd Jun 13, 2025
9 of 10 checks passed
@gfyrag gfyrag deleted the fix/experimental-features-bad-status-code branch June 13, 2025 15:07
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.

2 participants
0