From 90be1856da4b4ea5a4c5ab4d99dd7c9bd2170c29 Mon Sep 17 00:00:00 2001 From: Ben Kochie Date: Wed, 7 Feb 2024 10:51:00 +0100 Subject: [PATCH] Fix hwmon error capture Fix golangci-lint "ineffectual assignment" by correctly capturing any errors within the hwmon gathering loop. Signed-off-by: Ben Kochie --- collector/hwmon_linux.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/collector/hwmon_linux.go b/collector/hwmon_linux.go index 476eed7b30..a8086d309e 100644 --- a/collector/hwmon_linux.go +++ b/collector/hwmon_linux.go @@ -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) @@ -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 }