From 3c115b138d0ac5361eea7b8a0b21ef57cf9c2b71 Mon Sep 17 00:00:00 2001 From: Markus Lehtonen Date: Wed, 9 Sep 2026 08:36:18 +0300 Subject: [PATCH] pkg/monitor: fix linter errors Signed-off-by: Markus Lehtonen --- pkg/monitor/monitor.go | 8 +++++--- pkg/monitor/monitor_test.go | 8 +++++--- pkg/monitor/validate.go | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/pkg/monitor/monitor.go b/pkg/monitor/monitor.go index 5224992..2b678b1 100644 --- a/pkg/monitor/monitor.go +++ b/pkg/monitor/monitor.go @@ -355,10 +355,12 @@ func (m *Manager) AssignPID(key string, pid int) error { if err != nil { return fmt.Errorf("failed to open tasks file for key %s: %w", key, err) } - defer f.Close() - data := []byte(strconv.Itoa(pid) + "\n") if _, err := f.Write(data); err != nil { + f.Close() //nolint:errcheck // report the write error + return fmt.Errorf("failed to write pid %d for key %s: %w", pid, key, err) + } + if err := f.Close(); err != nil { return fmt.Errorf("failed to write pid %d for key %s: %w", pid, key, err) } log().Info("assigned PID to mon_group", "key", key, "pid", pid) @@ -411,7 +413,7 @@ func pidInTasksFile(path string, pid int) (bool, error) { } return false, fmt.Errorf("failed to open tasks file %s: %w", path, err) } - defer f.Close() + defer f.Close() //nolint:errcheck // read-only target := strconv.Itoa(pid) sc := bufio.NewScanner(f) diff --git a/pkg/monitor/monitor_test.go b/pkg/monitor/monitor_test.go index a8e151c..02948e1 100644 --- a/pkg/monitor/monitor_test.go +++ b/pkg/monitor/monitor_test.go @@ -927,7 +927,8 @@ func TestRemove_ConcurrentEnsureGroup(t *testing.T) { var wg sync.WaitGroup wg.Go(func() { - mgr.Remove("pod-uid-1") + // Racing with EnsureGroup, we're not interested in the error but the state (checked later) + _ = mgr.Remove("pod-uid-1") }) var ensureErr error wg.Go(func() { @@ -969,10 +970,11 @@ func TestRemove_ConcurrentReadCounters(t *testing.T) { go func() { defer close(done) for i := 0; i < 100; i++ { - mgr.ReadCounters("pod-uid-1") + // Racing with Remove below so errors are expected, we only assert on no panic/data race + _, _ = mgr.ReadCounters("pod-uid-1") } }() // Give the reader goroutine a head start, then remove. - mgr.Remove("pod-uid-1") + _ = mgr.Remove("pod-uid-1") <-done } diff --git a/pkg/monitor/validate.go b/pkg/monitor/validate.go index 08e2c0a..47e5b14 100644 --- a/pkg/monitor/validate.go +++ b/pkg/monitor/validate.go @@ -104,7 +104,7 @@ func isHex(s string) bool { return false } for _, c := range s { - if !((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')) { + if (c < '0' || c > '9') && (c < 'a' || c > 'f') && (c < 'A' || c > 'F') { return false } }