Skip to content

Commit

Permalink
Fix hwmon error capture (prometheus#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 <superq@gmail.com>
Signed-off-by: Vitaly Zhuravlev <v-zhuravlev@users.noreply.github.com>
  • Loading branch information
SuperQ authored and v-zhuravlev committed Nov 1, 2024
1 parent b2e4cb1 commit 3c3735f
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 3c3735f

Please sign in to comment.