Skip to content

Commit

Permalink
Fix hwmon error capture (#2915)
Browse files Browse the repository at this point in the history
Fix golangci-lint "ineffectual assignment" by correctly capturing any
errors within the hwmon gathering loop.

Signed-off-by: Ben Kochie <[email protected]>
  • Loading branch information
SuperQ authored Feb 7, 2024
1 parent fe78e7e commit 29fca60
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions collector/hwmon_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ func (c *hwMonCollector) Update(ch chan<- prometheus.Metric) error {
return err
}

var lastErr error
for _, hwDir := range hwmonFiles {
hwmonXPathName := filepath.Join(hwmonPathName, hwDir.Name())
fileInfo, err := os.Lstat(hwmonXPathName)
Expand All @@ -462,10 +463,10 @@ func (c *hwMonCollector) Update(ch chan<- prometheus.Metric) error {
continue
}

if lastErr := c.updateHwmon(ch, hwmonXPathName); lastErr != nil {
err = lastErr
if err = c.updateHwmon(ch, hwmonXPathName); err != nil {
lastErr = err
}
}

return err
return lastErr
}

0 comments on commit 29fca60

Please sign in to comment.