mirror of https://github.com/prometheus/prometheus
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
parent
e193579df8
commit
856de30c09
|
@ -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)
|
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)
|
f, err := os.Open(hintFile)
|
||||||
defer f.Close()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Could not open hint file %q: %s", hintFile, err)
|
t.Errorf("Could not open hint file %q: %s", hintFile, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
scanner := bufio.NewScanner(f)
|
scanner := bufio.NewScanner(f)
|
||||||
for _, want := range contentHintFile {
|
for _, want := range contentHintFile {
|
||||||
if !scanner.Scan() {
|
if !scanner.Scan() {
|
||||||
|
|
Loading…
Reference in New Issue