Skip to content

Commit

Permalink
fix: defer close after error check
Browse files Browse the repository at this point in the history
  • Loading branch information
luissimas committed Jun 24, 2024
1 parent aa5817e commit 3fc236b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions internal/collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3fc236b

Please sign in to comment.