Skip to content

Commit f559f4c

Browse files
committed
backend: improve error handling
When we're done with a file, ensure we close it, in case an error occurs unexpectedly, and handle the error from a Scanner object if we get one.
1 parent 1c213ee commit f559f4c

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

backend.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func findAllBackends(mainLoose *fileStorer, mainPacked *pack.Storage, root strin
4141
}
4242
return nil, err
4343
}
44+
defer f.Close()
4445

4546
scanner := bufio.NewScanner(f)
4647
for scanner.Scan() {
@@ -51,6 +52,11 @@ func findAllBackends(mainLoose *fileStorer, mainPacked *pack.Storage, root strin
5152
}
5253
storage = append(storage, pack)
5354
}
55+
56+
if err := scanner.Err(); err != nil {
57+
return nil, err
58+
}
59+
5460
return storage, nil
5561
}
5662

0 commit comments

Comments
 (0)