Skip to content

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

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

gfyrag
Copy link
Contributor

@gfyrag gfyrag commented Jun 13, 2025

Fixes LX-58

@gfyrag gfyrag requested a review from a team as a code owner June 13, 2025 14:57
Copy link

coderabbitai bot commented Jun 13, 2025

Walkthrough

The error handling for the ledger creation API was updated to treat attempts to use experimental features when disabled as a validation error, returning a 400 response. The end-to-end tests were refactored to explicitly cover scenarios with and without experimental features enabled, verifying the correct error responses in both cases.

Changes

File(s) Change Summary
internal/api/v2/controllers_ledgers_create.go Expanded error handling: treat ErrExperimentalFeaturesDisabled as a validation error (400 Bad Request).
test/e2e/api_ledgers_create_test.go Refactored tests to separate contexts for experimental features enabled/disabled; updated assertions and structure.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant API
    participant System

    Client->>API: POST /ledgers (with experimental features)
    API->>System: Validate ledger creation request
    alt Experimental features disabled
        System-->>API: Return ErrExperimentalFeaturesDisabled
        API-->>Client: 400 Bad Request (validation error)
    else Experimental features enabled
        System-->>API: Ledger created successfully
        API-->>Client: 201 Created
    end
Loading

Assessment against linked issues

Objective Addressed Explanation
Return 400 validation error when experimental features are disabled (LX-58)
Avoid returning 500/internal errors for disabled experimental features (LX-58)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes found.

Suggested reviewers

  • Dav-14
  • flemzord

Poem

A ledger’s tale, both old and new,
Now checks if features are allowed for you.
If experiments are off, it’s clear as day—
A gentle 400 sends you on your way.
With tests refactored, rabbits cheer,
For tidy code and logic here!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Commit Unit Tests in branch hotfix/v2.2/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: 0

🧹 Nitpick comments (4)
internal/api/v2/controllers_ledgers_create.go (1)

35-39: Consider extracting the validation-error list to a helper for maintainability

The inline switch predicate is starting to get long and error-prone as new validation errors are appended:

case errors.Is(err, system.ErrInvalidLedgerConfiguration{}) ||
     errors.Is(err, ledger.ErrInvalidLedgerName{})         ||
     errors.Is(err, ledger.ErrInvalidBucketName{})         ||
     errors.Is(err, system.ErrExperimentalFeaturesDisabled):

Moving this boolean to a small helper, e.g. isValidationError(err error) bool, will:

  • Keep the handler readable.
  • Avoid duplication if the same check is required elsewhere.
  • Make additions in future PRs less likely to introduce precedence mistakes.

This is a low-impact refactor that improves clarity.

test/e2e/api_ledgers_create_test.go (3)

24-32: DRY up duplicated test-server bootstrap

The two contexts spin up almost identical NewTestServer blocks, differing only by the ExperimentalFeatures flag.
Consider parameterising this setup to reduce duplication and the risk of the two paths diverging:

func newServer(enableExperimental bool) *TestServer {
    return NewTestServer(func() Configuration {
        cfg := Configuration{
            PostgresConfiguration: db.GetValue().ConnectionOptions(),
            Output:                GinkgoWriter,
            Debug:                 debug,
            NatsURL:               natsServer.GetValue().ClientURL(),
        }
        cfg.ExperimentalFeatures = enableExperimental
        return cfg
    })
}

Then:

testServer := newServer(false) // or true

This keeps the suite concise and makes feature-toggle differences explicit.

Also applies to: 64-73


45-47: specContext parameter is unused

JustBeforeEach(func(specContext SpecContext) { ... }) declares specContext but never references it, which triggers go vet’s unusedparam warning.

Either use the context (e.g. for timeouts/cancellation) or drop the parameter:

JustBeforeEach(func() {
    err = CreateLedger(ctx, testServer.GetValue(), createLedgerRequest)
})

51-59: Prefer HaveOccurred() for nil-check + readability

In several assertions you combine NotTo(BeNil()) / To(BeNil()) with error variables.
Gomega’s idiomatic helper is shorter and reads better:

Expect(err).To(HaveOccurred())      // instead of NotTo(BeNil())
Expect(err).NotTo(HaveOccurred())   // instead of To(BeNil())

This is stylistic, but adopting the common convention improves consistency across the codebase.

Also applies to: 91-99

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 26b7d16 and d199258.

📒 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 (1)
internal/api/v2/controllers_ledgers_create.go (1)
internal/controller/system/errors.go (1)
  • ErrExperimentalFeaturesDisabled (11-11)
⏰ 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: Add unit-test coverage for the new ErrExperimentalFeaturesDisabled branch

The additional errors.Is(err, system.ErrExperimentalFeaturesDisabled) check correctly classifies the error as a validation error.
However, the controller now has an extra branch that is not covered by the existing unit test suite for this handler.
Please add (or extend) a fast unit test – separate from the e2e tests – that:

  1. Mocks system.Controller.CreateLedger to return system.ErrExperimentalFeaturesDisabled.
  2. Verifies the handler responds with HTTP 400 and a validation error payload.

This guards against future regressions without relying solely on the heavier e2e flow.

@gfyrag gfyrag merged commit 65d41f1 into release/v2.2 Jun 13, 2025
8 checks passed
@gfyrag gfyrag deleted the hotfix/v2.2/experimental-features-bad-status-code branch June 13, 2025 15:35
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