From 52d436d38a53523a6ff8fb4ecb5adb01d1d6cc67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Fri, 8 Mar 2024 11:14:06 +0000 Subject: [PATCH] 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. --- shared.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/shared.go b/shared.go index 13546b98..719c21a0 100644 --- a/shared.go +++ b/shared.go @@ -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 }