From f559f4cdc892ce48ddcbcae53cbbe4179bd47826 Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Thu, 15 Nov 2018 15:18:53 +0000 Subject: [PATCH] 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. --- backend.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/backend.go b/backend.go index 0c310b1..fea385c 100644 --- a/backend.go +++ b/backend.go @@ -41,6 +41,7 @@ func findAllBackends(mainLoose *fileStorer, mainPacked *pack.Storage, root strin } return nil, err } + defer f.Close() scanner := bufio.NewScanner(f) for scanner.Scan() { @@ -51,6 +52,11 @@ func findAllBackends(mainLoose *fileStorer, mainPacked *pack.Storage, root strin } storage = append(storage, pack) } + + if err := scanner.Err(); err != nil { + return nil, err + } + return storage, nil }