Immediately check for errors on fs.Open

Found with github.com/dominikh/go-staticcheck
This commit is contained in:
Cameron Moore 2016-07-01 10:44:25 -05:00
parent 1a8ecf8b9d
commit 8bf3f8b71f
2 changed files with 4 additions and 4 deletions

View File

@ -394,13 +394,13 @@ func TestWriteAt(t *testing.T) {
}
f2, err := fs.Open(f.Name())
if err != nil {
t.Fatalf("%v: ReadFile %s: %v", fs.Name(), f.Name(), err)
}
defer f2.Close()
buf := new(bytes.Buffer)
buf.ReadFrom(f2)
b := buf.Bytes()
if err != nil {
t.Fatalf("%v: ReadFile %s: %v", fs.Name(), f.Name(), err)
}
if string(b) != "hello, WORLD\n" {
t.Fatalf("after write: have %q want %q", string(b), "hello, WORLD\n")
}

View File

@ -295,10 +295,10 @@ func IsEmpty(fs Fs, path string) (bool, error) {
}
if fi.IsDir() {
f, err := fs.Open(path)
defer f.Close()
if err != nil {
return false, err
}
defer f.Close()
list, err := f.Readdir(-1)
return len(list) == 0, nil
}