-
Notifications
You must be signed in to change notification settings - Fork 311
fix: properly store errors in Iterator.Next() method #1090
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
Conversation
WalkthroughThe Changes
Suggested reviewers
Poem
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (1.64.8)Error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Co-authored-by: yihuang <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you fix the code format, I think my code suggestion messed up the spaces and tabs.
corrected, |
|
@yihuang Hello, is this pull request alright now? Or I need to wait for more reviews? |
|
This looks good @GarmashAlex could you add a test to verify that this is working? |
|
@aljo242 Done |
There was a problem hiding this 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 (2)
iterator_test.go (2)
386-391: Unused mock implementation.The
mockNodeDBtype is defined but not actually used in the test case below. Consider either using this mock or removing it to avoid confusion.-// mockNodeDB always returns an error for GetNode -type mockNodeDB struct{} - -func (m *mockNodeDB) GetNode(_ []byte) (*Node, error) { - return nil, errors.New("mock nodeDB error") -} -
393-419: Good test for error handling in Iterator.Next()This test effectively validates the fix for storing errors in the Iterator.Next() method. It creates a scenario where a node retrieval will fail due to a missing node key, then verifies that the iterator properly captures and exposes the error.
A few minor suggestions:
- Add a comment explaining that this test specifically validates the fix in Iterator.Next() for properly storing errors
- Consider making the error message check less brittle by using a more general assertion
func TestIterator_Next_ErrorHandling(t *testing.T) { + // Test that errors from traversal.next() are properly stored in the iterator's error field db := dbm.NewMemDB() ndb := newNodeDB(db, 0, DefaultOptions(), NewNopLogger()) tree := &ImmutableTree{ndb: ndb}
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting
📒 Files selected for processing (1)
iterator_test.go(2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
iterator_test.go (6)
node.go (1)
Node(59-75)db/memdb.go (1)
NewMemDB(55-60)options.go (1)
DefaultOptions(95-97)logger.go (1)
NewNopLogger(25-27)immutable_tree.go (1)
ImmutableTree(16-23)iterator.go (1)
Iterator(172-182)
🔇 Additional comments (2)
iterator_test.go (2)
4-4: Import added appropriately.The
errorspackage is correctly imported to support the new test case that validates error handling.
415-418: Comprehensive assertions for error handling.The test correctly verifies all aspects of the iterator's behavior after an error:
- The iterator becomes invalid
- The error is properly set in the iterator
- The error message contains expected content
This provides good coverage for the fix described in the PR.
|
@Mergifyio backport release/v1.2.x |
|
@Mergifyio backport release/v1.3.x |
✅ Backports have been created
|
✅ Backports have been created
|
|
@aljo242 corrected lint error |
Co-authored-by: yihuang <[email protected]> Co-authored-by: Alex | Interchain Labs <[email protected]> (cherry picked from commit 4027b8d)
Co-authored-by: yihuang <[email protected]> Co-authored-by: Alex | Interchain Labs <[email protected]> (cherry picked from commit 4027b8d)
This commit fixes the error handling in the Iterator.Next() method
by explicitly storing errors from traversal.next() in the iterator's
error field. Previously, errors were silently dropped, causing them to
be unavailable through the Error() method.
The fix:
in both error and end-of-traversal cases
Summary by CodeRabbit