-
Notifications
You must be signed in to change notification settings - Fork 0
refactor(core): improve multihasher seek error handling and close behavior #882
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
|
Warning Rate limit exceeded@pcfreak30 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 1 minutes and 21 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (2)
WalkthroughThe changes introduce seeking support and enhanced closing behavior to the Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant MultiHasher
participant Source (io.Reader/io.Seeker/io.Closer)
participant Hashers
Caller->>MultiHasher: Seek(offset, whence)
alt Source supports io.Seeker
MultiHasher->>Source: Seek(offset, whence)
Source-->>MultiHasher: newPos, err
MultiHasher->>Hashers: Reset all hashers
MultiHasher-->>Caller: newPos, err
else Source doesn't support io.Seeker
MultiHasher-->>Caller: error
end
Caller->>MultiHasher: Close()
alt Source supports io.Closer
MultiHasher->>Source: Close()
Source-->>MultiHasher: err
MultiHasher-->>Caller: err
else
MultiHasher-->>Caller: nil
end
Possibly related PRs
Poem
✨ 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 (
|
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 (1)
core/multihasher.go (1)
291-315
: Consider using more specific error types for different failure scenarios.The method correctly implements seeking functionality and properly resets hashers after position changes. However, returning
io.ErrUnexpectedEOF
for all error cases might not be the most appropriate:
- Line 293: When source is nil,
io.ErrUnexpectedEOF
is reasonable- Line 298: When source doesn't implement
io.Seeker
, considererrors.New("seek not supported")
or a custom error- Line 304: When the underlying seek fails, consider returning the original error instead of wrapping it
Consider this more specific error handling:
func (m *MultiHasher) Seek(offset int64, whence int) (int64, error) { if m.source == nil { return 0, io.ErrUnexpectedEOF } seeker, ok := m.source.(io.Seeker) if !ok { - return 0, io.ErrUnexpectedEOF + return 0, errors.New("source does not support seeking") } // Seek the underlying reader newPos, err := seeker.Seek(offset, whence) if err != nil { - return newPos, io.ErrUnexpectedEOF + return newPos, err }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
core/internal/core_tests/multihasher_test.go
(3 hunks)core/multihasher.go
(4 hunks)
🔇 Additional comments (9)
core/multihasher.go (4)
33-37
: LGTM! Good practice for interface compliance verification.The explicit interface assertions ensure compile-time verification that
MultiHasher
implements the expected interfaces. This is a best practice for interface compliance.
317-326
: LGTM! Proper implementation of io.Closer interface.The method correctly:
- Waits for worker pool completion before closing
- Closes the source reader if it implements io.Closer
- Returns appropriate errors
328-335
: LGTM! Thread-safe getter method for testing.The method properly uses mutex for thread safety and is clearly documented as being for testing purposes only.
81-86
: Fix the error handling logic in Close call.The current logic only returns the original seek error if the Close call succeeds, but returns the Close error if it fails. This seems incorrect - you should prioritize the original error.
Apply this fix:
if _, err := seeker.Seek(0, io.SeekStart); err != nil { - err2 := hasher.Close() - if err2 != nil { - return nil, err - } + if closeErr := hasher.Close(); closeErr != nil { + // Log the close error but return the original seek error + return nil, err + } return nil, err }Likely an incorrect or invalid review comment.
core/internal/core_tests/multihasher_test.go (5)
27-27
: LGTM! Error type now matches the Seek method implementation.The change to return
io.ErrUnexpectedEOF
aligns with the error handling in the mainSeek
method implementation.
620-644
: LGTM! Comprehensive test for Close method with closable source.The test properly verifies that:
- The Close method returns no error
- The underlying source remains intact after closing
- The functionality works correctly with io.ReadCloser
646-688
: LGTM! Thorough test coverage for Seek functionality.The test comprehensively covers:
- Seeking to start, end, and middle positions
- Proper position returns
- Hash reset verification after seeking
The use of
GetHashes()
method for verification is appropriate for testing purposes.
690-725
: LGTM! Good error case coverage for Seek method.The tests properly cover both error scenarios:
- Non-seekable source returning the expected error
- Failing seek operations during initialization
The error assertions match the expected behavior from the implementation.
883-888
: LGTM! Improved error handling in test cleanup.The deferred Close call now properly asserts that no error occurs, which aligns with the updated Close method signature.
…avior - Changed seek error from generic "seek error" to `io.ErrUnexpectedEOF` for consistency - Added proper error handling for closing seekable sources - Implemented `io.Seeker` interface with position reset functionality - Added test cases for seek and close operations
4355478
to
1d548d1
Compare
io.ErrUnexpectedEOF
for consistencyio.Seeker
interface with position reset functionalitySummary by CodeRabbit
New Features
Bug Fixes
Tests