Check error before defer closing

If an error is returned the file might be nil and a Close call
would cause a panic.
pull/2186/head
Fabian Reinartz 2016-11-13 18:16:02 +01:00
parent e193579df8
commit 856de30c09
1 changed files with 2 additions and 1 deletions

View File

@ -1097,11 +1097,12 @@ func TestQuranatineSeriesFile(t *testing.T) {
t.Errorf("Unexpected state of quarantined file %q. Expected it to exist: %t. os.Stat returned: %s.", quarantinedFile, seriesFileShouldExist, err)
}
f, err := os.Open(hintFile)
defer f.Close()
if err != nil {
t.Errorf("Could not open hint file %q: %s", hintFile, err)
return
}
defer f.Close()
scanner := bufio.NewScanner(f)
for _, want := range contentHintFile {
if !scanner.Scan() {