From 3fc236b1a6527a75fb801b78ff4789ba6676619c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Simas?= Date: Mon, 24 Jun 2024 08:57:10 -0300 Subject: [PATCH] fix: defer close after error check --- internal/collector/collector.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/collector/collector.go b/internal/collector/collector.go index 6d47073..a8feb79 100644 --- a/internal/collector/collector.go +++ b/internal/collector/collector.go @@ -72,17 +72,17 @@ func (c *Collector) collectMetrics(root fs.FS) (metrics.Metrics, error) { } f, err := root.Open(path) - defer f.Close() if err != nil { slog.Error("Error opening file", slog.Any("error", err), slog.String("path", path)) return nil } + defer f.Close() _, err = buf.ReadFrom(f) - defer buf.Reset() if err != nil { slog.Error("Error reading file into buffer", slog.Any("error", err), slog.String("path", path)) return nil } + defer buf.Reset() metrics := CollectNoteMetrics(buf.Bytes()) notes[path] = metrics linkCount += metrics.LinkCount