remove err conditional that was never met

gopls correctly pointed out that the err==nil check was never met,
as err was assigned and we returned early when err!=nil.

This was an oversight when I wrote this; when Encode fails,
we shouldn't return, because we still want to close the file.
We don't defer because we want to check the error; explain that.
pull/846/head
Daniel Martí 2 months ago committed by pagran
parent d2beda1f00
commit 52d436d38a

@ -128,9 +128,8 @@ func writeGobExclusive(name string, val any) error {
if err != nil {
return err
}
if err := gob.NewEncoder(f).Encode(val); err != nil {
return err
}
// Always close the file, and return the first error we get.
err = gob.NewEncoder(f).Encode(val)
if err2 := f.Close(); err == nil {
err = err2
}

Loading…
Cancel
Save