-
Notifications
You must be signed in to change notification settings - Fork 1
improve error management when the file contents is not available #17
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
📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the 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. Comment |
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
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
lib/libhpsm.go (1)
178-195: Fix temp-file leak and respect the Threshold parameter.
If the remote file is too small, the/tmp/<md5>file is never removed, and theThresholdargument is ignored, which can yield incorrect comparisons when callers supply different values.🛠️ Proposed fix
- err := GetFileContent(srcEndpoint+MD5, "/tmp/"+MD5) + tmpPath := "/tmp/" + MD5 + err := GetFileContent(srcEndpoint+MD5, tmpPath) - if err == nil { - hashRemote := proc.GetLineHashes("/tmp/" + MD5) - if len(hashRemote) <= 5 { - return []model.Range{}, fmt.Errorf("remote file too small or not found") - } - - u.Rm("/tmp/" + MD5) - return proc.Compare(local, hashRemote, uint32(5)), nil - } else { - return []model.Range{}, fmt.Errorf("remote file not found or inaccessible") - } + if err != nil { + return []model.Range{}, fmt.Errorf("remote file not found or inaccessible") + } + + defer u.Rm(tmpPath) + + hashRemote := proc.GetLineHashes(tmpPath) + if uint32(len(hashRemote)) <= Threshold { + return []model.Range{}, fmt.Errorf("remote file too small or not found") + } + + return proc.Compare(local, hashRemote, Threshold), nil
🧹 Nitpick comments (1)
lib/libhpsm.go (1)
147-154: Optional: centralize error-range construction.
The same-1/-1/-1%struct is built in multiple call sites; a small helper would reduce duplication and keep the sentinel format consistent.
scanoss-qg
left a comment
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.
LGTM
|
Improve remote file contents error management |
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.