Skip to content

Conversation

@mscasso-scanoss
Copy link
Contributor

@mscasso-scanoss mscasso-scanoss commented Jan 22, 2026

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling to return descriptive error messages when remote file validation or retrieval fails, replacing placeholder values with clear error feedback.
    • Enhanced error reporting throughout the file processing pipeline to enable better troubleshooting and diagnostics when operations encounter failures.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 22, 2026

📝 Walkthrough

Walkthrough

The localProcessHPSM function signature was updated to return both []model.Range and error. Call sites (HPSM and ProcessHPSM) now handle error returns by constructing error range structs with sentinel values (-1 for local/remote, "-1%" for matched) instead of propagating nil.

Changes

Cohort / File(s) Summary
Error Handling Implementation
lib/libhpsm.go
Function localProcessHPSM signature changed to return ([]model.Range, error). Error cases now return empty slice with descriptive error; call sites updated to check error and construct sentinel error ranges on failure.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A hop, a skip, errors now speak clear,
Where silence once lived, clarity's here,
localProcessHPSM now dual-returns with grace,
Error paths handled with sentinel's embrace!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: improving error management by modifying localProcessHPSM to return errors when file retrieval or validation fails, rather than returning placeholder values.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a 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 the Threshold argument 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.

Copy link
Contributor

@scanoss-qg scanoss-qg left a comment

Choose a reason for hiding this comment

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

LGTM

@mscasso-scanoss
Copy link
Contributor Author

Improve remote file contents error management

@mscasso-scanoss mscasso-scanoss merged commit c9eb81e into main Feb 2, 2026
2 checks passed
@mscasso-scanoss mscasso-scanoss deleted the mscasso/fix/improve_error_management branch February 2, 2026 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants