From 104820f4fe56b6a88b87071f4ff0769b0b317d86 Mon Sep 17 00:00:00 2001 From: Deivid Soto Date: Mon, 30 Mar 2026 23:31:06 +0200 Subject: [PATCH] fix(lint): resolve errcheck and bodyclose warnings for golangci-lint v2 --- internal/agent/transport_ws.go | 5 ++++- internal/arr/discover_e2e_test.go | 2 +- internal/config/config.go | 2 +- internal/config/config_test.go | 4 ++-- internal/config/paths_test.go | 2 +- internal/library/mediainfo/ffprobe_download.go | 4 ++-- internal/mediaserver/detect.go | 4 ++-- 7 files changed, 13 insertions(+), 10 deletions(-) diff --git a/internal/agent/transport_ws.go b/internal/agent/transport_ws.go index bdb7343..8d2f956 100644 --- a/internal/agent/transport_ws.go +++ b/internal/agent/transport_ws.go @@ -67,7 +67,10 @@ func (t *WSTransport) Connect(ctx context.Context) error { wsURLWithKey += sep + "key=" + t.apiKey } - conn, _, err := dialer.DialContext(ctx, wsURLWithKey, header) + conn, wsResp, err := dialer.DialContext(ctx, wsURLWithKey, header) + if wsResp != nil && wsResp.Body != nil { + defer wsResp.Body.Close() //nolint:errcheck + } if err != nil { return fmt.Errorf("ws dial: %w", err) } diff --git a/internal/arr/discover_e2e_test.go b/internal/arr/discover_e2e_test.go index 6a0a07a..0245ae2 100644 --- a/internal/arr/discover_e2e_test.go +++ b/internal/arr/discover_e2e_test.go @@ -21,7 +21,7 @@ func TestDiscoverE2E(t *testing.T) { if err != nil { t.Skipf("Port %s not reachable, skipping", port) } - conn.Close() + _ = conn.Close() } t.Run("Discover", func(t *testing.T) { diff --git a/internal/config/config.go b/internal/config/config.go index 04195b7..c4948ef 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -171,7 +171,7 @@ func Save(cfg Config, path string) error { } if err := os.Rename(tmpPath, path); err != nil { - os.Remove(tmpPath) + _ = os.Remove(tmpPath) return fmt.Errorf("rename config: %w", err) } diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 3190399..e9746e4 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -93,7 +93,7 @@ func TestLoadPreservesDefaults(t *testing.T) { path := filepath.Join(tmp, "config.toml") // Write partial config (only auth section) - os.WriteFile(path, []byte(`[auth] + _ = os.WriteFile(path, []byte(`[auth] api_key = "tc_partial" `), 0o644) @@ -193,7 +193,7 @@ func TestParseSpeed(t *testing.T) { func TestLoadInvalidTOML(t *testing.T) { tmp := t.TempDir() path := filepath.Join(tmp, "config.toml") - os.WriteFile(path, []byte(`not valid toml [[[`), 0o644) + _ = os.WriteFile(path, []byte(`not valid toml [[[`), 0o644) _, err := Load(path) if err == nil { diff --git a/internal/config/paths_test.go b/internal/config/paths_test.go index ed93044..e3fdb33 100644 --- a/internal/config/paths_test.go +++ b/internal/config/paths_test.go @@ -43,7 +43,7 @@ func TestDirOverrideEnv(t *testing.T) { func TestDirXDGOverride(t *testing.T) { // Clear the custom env so XDG takes effect - os.Unsetenv("UNARR_CONFIG_DIR") + _ = os.Unsetenv("UNARR_CONFIG_DIR") t.Setenv("XDG_CONFIG_HOME", "/xdg/config") dir := Dir() diff --git a/internal/library/mediainfo/ffprobe_download.go b/internal/library/mediainfo/ffprobe_download.go index cf2cc06..0e4a739 100644 --- a/internal/library/mediainfo/ffprobe_download.go +++ b/internal/library/mediainfo/ffprobe_download.go @@ -97,7 +97,7 @@ func DownloadFFprobe() (string, error) { if err != nil { return "", fmt.Errorf("download failed: %w", err) } - defer resp.Body.Close() + defer resp.Body.Close() //nolint:errcheck // best-effort close if resp.StatusCode != http.StatusOK { return "", fmt.Errorf("download failed: HTTP %d", resp.StatusCode) @@ -167,7 +167,7 @@ func extractFromZip(data []byte, target string) ([]byte, error) { if err != nil { return nil, fmt.Errorf("cannot extract %s from archive: %w", target, err) } - defer rc.Close() + defer rc.Close() //nolint:errcheck // best-effort close return io.ReadAll(rc) } } diff --git a/internal/mediaserver/detect.go b/internal/mediaserver/detect.go index e0b3030..0680519 100644 --- a/internal/mediaserver/detect.go +++ b/internal/mediaserver/detect.go @@ -113,7 +113,7 @@ func plexLibraryPaths() []string { if err != nil { return nil } - defer resp.Body.Close() + defer resp.Body.Close() //nolint:errcheck // best-effort close if resp.StatusCode != 200 { return nil @@ -200,7 +200,7 @@ func jellyfinLibraryPaths(baseURL string) []string { if err != nil { return nil } - defer resp.Body.Close() + defer resp.Body.Close() //nolint:errcheck // best-effort close if resp.StatusCode != 200 { return nil