fix: return the .idx open error from SaveToIdx

The bare return gave back the nil named result, so a failure to open the
index looked like a successful save.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Chris LuandClaude Opus 5.5 committed 2026-11-23 05:15:33 -08:00
1 parent 61bfc9d7b2
commit 8ca0c781c0
2 files changed
+9 -1

No files matched your search

+1 -1
View File
@@ -197,7 +197,7 @@ func fixEcxFromShardsInDir(basePath string, files []fs.DirEntry) bool {
func SaveToIdx(scaner *VolumeFileScanner4Fix, idxName string) (ret error) {
idxFile, err := os.OpenFile(idxName, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
return
return err
}
defer func() {
idxFile.Close()
+8
View File
@@ -260,3 +260,11 @@ func TestFixTruncatedDeleteKeepsKeyDeleted(t *testing.T) {
}
}
}
func TestSaveToIdxReportsOpenError(t *testing.T) {
nm := needle_map.NewMemDb()
defer nm.Close()
if err := SaveToIdx(&VolumeFileScanner4Fix{nm: nm}, t.TempDir()); err == nil {
t.Error("expected an error when the .idx path cannot be opened")
}
}