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.
This commit is contained in:
Daniel Martí
2024-03-08 11:14:06 +00:00
committed by pagran
parent d2beda1f00
commit 52d436d38a

View File

@@ -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
}