Skip to content
Merged
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
11 changes: 11 additions & 0 deletions store/gaskv/store.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gaskv

import (
"errors"
"io"

"cosmossdk.io/store/types"
Expand Down Expand Up @@ -132,6 +133,16 @@ func (gs *GStore[V]) iterator(start, end []byte, ascending bool) types.GIterator
parent = gs.parent.ReverseIterator(start, end)
}

// release parent open iterator if we panic during consumeSeekGas() and re-panic
defer func() {
if r := recover(); r != nil {
if err := parent.Close(); err != nil {
r = errors.Join(r.(error), err)
}
panic(r)
}
}()
Comment on lines +136 to +144
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix unsafe type assertion in panic path (can double-panic).

If the panic value r is not an error (common: string), r.(error) will itself panic, obscuring the original failure. Convert non-error panics before joining.

Apply this diff:

-   if err := parent.Close(); err != nil {
-       r = errors.Join(r.(error), err)
-   }
+   if err := parent.Close(); err != nil {
+       if e, ok := r.(error); ok {
+           r = errors.Join(e, err)
+       } else {
+           // convert arbitrary panic payloads (e.g., strings) to error before join
+           r = errors.Join(fmt.Errorf("%v", r), err)
+       }
+   }

And add the missing import:

 import (
+    "fmt"
     "errors"
     "io"
📝 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
// release parent open iterator if we panic during consumeSeekGas() and re-panic
defer func() {
if r := recover(); r != nil {
if err := parent.Close(); err != nil {
r = errors.Join(r.(error), err)
}
panic(r)
}
}()
// release parent open iterator if we panic during consumeSeekGas() and re-panic
defer func() {
if r := recover(); r != nil {
if err := parent.Close(); err != nil {
if e, ok := r.(error); ok {
r = errors.Join(e, err)
} else {
// convert arbitrary panic payloads (e.g., strings) to error before join
r = errors.Join(fmt.Errorf("%v", r), err)
}
}
panic(r)
}
}()
🤖 Prompt for AI Agents
In store/gaskv/store.go around lines 136-144, the deferred panic handler
unsafely asserts r.(error) which can itself panic if r isn't an error; change it
to normalize r into an error before joining: if r is already an error use it,
otherwise convert with fmt.Errorf("%v", r), then if parent.Close() returns an
error use errors.Join(normalizedError, closeErr) and re-panic the joined error;
also add the required imports for "errors" and "fmt".


gi := newGasIterator(gs.gasMeter, gs.gasConfig, parent, gs.valueLen)
gi.consumeSeekGas()

Expand Down
Loading