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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion internal/api/v2/controllers_ledgers_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ func createLedger(systemController system.Controller) http.HandlerFunc {
switch {
case errors.Is(err, system.ErrInvalidLedgerConfiguration{}) ||
errors.Is(err, ledger.ErrInvalidLedgerName{}) ||
errors.Is(err, ledger.ErrInvalidBucketName{}):
errors.Is(err, ledger.ErrInvalidBucketName{}) ||
errors.Is(err, system.ErrExperimentalFeaturesDisabled):
api.BadRequest(w, common.ErrValidation, err)
case errors.Is(err, system.ErrBucketOutdated):
api.BadRequest(w, common.ErrOutdatedSchema, err)
Expand Down
229 changes: 136 additions & 93 deletions test/e2e/api_ledgers_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,121 +27,164 @@ var _ = Context("Ledger engine tests", func() {
natsURL = DeferMap(natsServer, (*natstesting.NatsServer).ClientURL)
)

testServer := ginkgo.DeferTestServer(
DeferMap(db, (*pgtesting.Database).ConnectionOptions),
testservice.WithInstruments(
testservice.NatsInstrumentation(natsURL),
testservice.DebugInstrumentation(debug),
testservice.OutputInstrumentation(GinkgoWriter),
ExperimentalFeaturesInstrumentation(),
),
testservice.WithLogger(GinkgoT()),
)

When("creating a new ledger", func() {
var (
createLedgerRequest operations.V2CreateLedgerRequest
err error
Context("without experimental features", func() {
testServer := ginkgo.DeferTestServer(
DeferMap(db, (*pgtesting.Database).ConnectionOptions),
testservice.WithInstruments(
testservice.NatsInstrumentation(natsURL),
testservice.DebugInstrumentation(debug),
testservice.OutputInstrumentation(GinkgoWriter),
),
testservice.WithLogger(GinkgoT()),
)
BeforeEach(func() {
createLedgerRequest = operations.V2CreateLedgerRequest{
Ledger: "foo",
V2CreateLedgerRequest: components.V2CreateLedgerRequest{},
}
})
JustBeforeEach(func(specContext SpecContext) {
_, err = Wait(specContext, DeferClient(testServer)).Ledger.V2.CreateLedger(ctx, createLedgerRequest)
})
It("should be ok", func() {
Expect(err).To(BeNil())
})
Context("with specific features set", func() {

When("creating a new ledger", func() {
var (
createLedgerRequest operations.V2CreateLedgerRequest
err error
)
BeforeEach(func() {
createLedgerRequest.V2CreateLedgerRequest.Features = features.MinimalFeatureSet.
With(features.FeatureMovesHistoryPostCommitEffectiveVolumes, "DISABLED")
createLedgerRequest = operations.V2CreateLedgerRequest{
Ledger: "foo",
V2CreateLedgerRequest: components.V2CreateLedgerRequest{},
}
})
JustBeforeEach(func(specContext SpecContext) {
_, err = Wait(specContext, DeferClient(testServer)).Ledger.V2.CreateLedger(ctx, createLedgerRequest)
})
It("should be ok", func() {
Expect(err).To(BeNil())
})
})
Context("with invalid feature configuration", func() {
BeforeEach(func() {
createLedgerRequest.V2CreateLedgerRequest.Features = features.MinimalFeatureSet.
With(features.FeatureMovesHistoryPostCommitEffectiveVolumes, "XXX")
})
It("should fail", func() {
Expect(err).To(HaveErrorCode(string(components.V2ErrorsEnumValidation)))
Context("with specific features set", func() {
BeforeEach(func() {
createLedgerRequest.V2CreateLedgerRequest.Features = features.MinimalFeatureSet.
With(features.FeatureMovesHistoryPostCommitEffectiveVolumes, "DISABLED")
})
It("should fail", func() {
Expect(err).NotTo(BeNil())
Expect(err).To(HaveErrorCode(string(components.V2ErrorsEnumValidation)))
})
})
})
Context("with invalid feature name", func() {
})

Context("with experimental features", func() {
testServer := ginkgo.DeferTestServer(
DeferMap(db, (*pgtesting.Database).ConnectionOptions),
testservice.WithInstruments(
testservice.NatsInstrumentation(natsURL),
testservice.DebugInstrumentation(debug),
testservice.OutputInstrumentation(GinkgoWriter),
ExperimentalFeaturesInstrumentation(),
),
testservice.WithLogger(GinkgoT()),
)

When("creating a new ledger", func() {
var (
createLedgerRequest operations.V2CreateLedgerRequest
err error
)
BeforeEach(func() {
createLedgerRequest.V2CreateLedgerRequest.Features = features.MinimalFeatureSet.
With("foo", "XXX")
})
It("should fail", func() {
Expect(err).To(HaveErrorCode(string(components.V2ErrorsEnumValidation)))
createLedgerRequest = operations.V2CreateLedgerRequest{
Ledger: "foo",
V2CreateLedgerRequest: components.V2CreateLedgerRequest{},
}
})
})
Context("trying to create another ledger with the same name", func() {
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)))
_, err = Wait(specContext, DeferClient(testServer)).Ledger.V2.CreateLedger(ctx, createLedgerRequest)
})
It("should fail", func() {})
})
Context("bucket naming convention depends on the database 63 bytes length (pg constraint)", func() {
BeforeEach(func() {
createLedgerRequest.V2CreateLedgerRequest.Bucket = pointer.For(strings.Repeat("a", 64))
It("should be ok", func() {
Expect(err).To(BeNil())
})
It("should fail with > 63 characters in ledger or bucket name", func() {
Expect(err).To(HaveOccurred())
Context("with specific features set", func() {
BeforeEach(func() {
createLedgerRequest.V2CreateLedgerRequest.Features = features.MinimalFeatureSet.
With(features.FeatureMovesHistoryPostCommitEffectiveVolumes, "DISABLED")
})
It("should be ok", func() {
Expect(err).To(BeNil())
})
})
})
Context("With metadata", func() {
BeforeEach(func() {
createLedgerRequest.V2CreateLedgerRequest.Metadata = map[string]string{
"foo": "bar",
}
Context("with invalid feature configuration", func() {
BeforeEach(func() {
createLedgerRequest.V2CreateLedgerRequest.Features = features.MinimalFeatureSet.
With(features.FeatureMovesHistoryPostCommitEffectiveVolumes, "XXX")
})
It("should fail", func() {
Expect(err).To(HaveErrorCode(string(components.V2ErrorsEnumValidation)))
})
})
It("Should be ok", func(specContext SpecContext) {
ledger, err := Wait(specContext, DeferClient(testServer)).Ledger.V2.GetLedger(ctx, operations.V2GetLedgerRequest{
Ledger: createLedgerRequest.Ledger,
Context("with invalid feature name", func() {
BeforeEach(func() {
createLedgerRequest.V2CreateLedgerRequest.Features = features.MinimalFeatureSet.
With("foo", "XXX")
})
It("should fail", func() {
Expect(err).To(HaveErrorCode(string(components.V2ErrorsEnumValidation)))
})
Expect(err).To(BeNil())
Expect(ledger.V2GetLedgerResponse.Data.Metadata).To(Equal(createLedgerRequest.V2CreateLedgerRequest.Metadata))
})
})
Context("with invalid ledger name", func() {
BeforeEach(func() {
createLedgerRequest.Ledger = "invalid\\name\\contains\\some\\backslash"
Context("trying to create another ledger with the same name", func() {
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)))
})
Comment on lines +128 to +134
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.

It("should fail", func() {})
})
It("should fail", func() {
Expect(err).NotTo(BeNil())
Expect(err).To(HaveErrorCode(string(components.V2ErrorsEnumValidation)))
Context("bucket naming convention depends on the database 63 bytes length (pg constraint)", func() {
BeforeEach(func() {
createLedgerRequest.V2CreateLedgerRequest.Bucket = pointer.For(strings.Repeat("a", 64))
})
It("should fail with > 63 characters in ledger or bucket name", func() {
Expect(err).To(HaveOccurred())
})
})
})
Context("with invalid bucket name", func() {
BeforeEach(func() {
createLedgerRequest.V2CreateLedgerRequest = components.V2CreateLedgerRequest{
Bucket: pointer.For("invalid\\name\\contains\\some\\backslash"),
}
Context("With metadata", func() {
BeforeEach(func() {
createLedgerRequest.V2CreateLedgerRequest.Metadata = map[string]string{
"foo": "bar",
}
})
It("Should be ok", func(specContext SpecContext) {
ledger, err := Wait(specContext, DeferClient(testServer)).Ledger.V2.GetLedger(ctx, operations.V2GetLedgerRequest{
Ledger: createLedgerRequest.Ledger,
})
Expect(err).To(BeNil())
Expect(ledger.V2GetLedgerResponse.Data.Metadata).To(Equal(createLedgerRequest.V2CreateLedgerRequest.Metadata))
})
})
It("should fail", func() {
Expect(err).NotTo(BeNil())
Expect(err).To(HaveErrorCode(string(components.V2ErrorsEnumValidation)))
Context("with invalid ledger name", func() {
BeforeEach(func() {
createLedgerRequest.Ledger = "invalid\\name\\contains\\some\\backslash"
})
It("should fail", func() {
Expect(err).NotTo(BeNil())
Expect(err).To(HaveErrorCode(string(components.V2ErrorsEnumValidation)))
})
})
})
Context("on alternate bucket", func() {
BeforeEach(func() {
createLedgerRequest.V2CreateLedgerRequest = components.V2CreateLedgerRequest{
Bucket: pointer.For("bucket0"),
}
Context("with invalid bucket name", func() {
BeforeEach(func() {
createLedgerRequest.V2CreateLedgerRequest = components.V2CreateLedgerRequest{
Bucket: pointer.For("invalid\\name\\contains\\some\\backslash"),
}
})
It("should fail", func() {
Expect(err).NotTo(BeNil())
Expect(err).To(HaveErrorCode(string(components.V2ErrorsEnumValidation)))
})
})
It("should be ok", func() {
Expect(err).To(BeNil())
Context("on alternate bucket", func() {
BeforeEach(func() {
createLedgerRequest.V2CreateLedgerRequest = components.V2CreateLedgerRequest{
Bucket: pointer.For("bucket0"),
}
})
It("should be ok", func() {
Expect(err).To(BeNil())
})
})
})
})
Expand Down
Loading