From 3607920601ce12e22651c0002a0a24d83c3800a2 Mon Sep 17 00:00:00 2001 From: Mathias Bergqvist Date: Thu, 23 Apr 2026 16:20:59 +0200 Subject: [PATCH] fix(lint): resolve all errcheck violations in ingestion module --- ingestion/internal/llm/client.go | 4 ++-- ingestion/internal/llm/client_test.go | 6 +++--- ingestion/internal/pipeline/pipeline_test.go | 6 +++--- ingestion/internal/watcher/watcher.go | 8 ++++---- ingestion/internal/wiki/inventory.go | 2 +- ingestion/internal/wiki/log.go | 4 ++-- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/ingestion/internal/llm/client.go b/ingestion/internal/llm/client.go index 4fac2d5..ccdb029 100644 --- a/ingestion/internal/llm/client.go +++ b/ingestion/internal/llm/client.go @@ -81,7 +81,7 @@ func (c *Client) Complete(ctx context.Context, system, user string) (string, err } if resp.StatusCode == http.StatusTooManyRequests { - resp.Body.Close() + _ = resp.Body.Close() wait := 5 * time.Second if ra := resp.Header.Get("Retry-After"); ra != "" { if secs, err := strconv.Atoi(ra); err == nil { @@ -98,7 +98,7 @@ func (c *Client) Complete(ctx context.Context, system, user string) (string, err return "", fmt.Errorf("retry LLM call: %w", err) } } - defer resp.Body.Close() + defer resp.Body.Close() //nolint:errcheck out, err := io.ReadAll(resp.Body) if err != nil { diff --git a/ingestion/internal/llm/client_test.go b/ingestion/internal/llm/client_test.go index 7101f96..621f811 100644 --- a/ingestion/internal/llm/client_test.go +++ b/ingestion/internal/llm/client_test.go @@ -18,7 +18,7 @@ func mockServer(t *testing.T, response string) *httptest.Server { assert.Equal(t, "/chat/completions", r.URL.Path) assert.Equal(t, "application/json", r.Header.Get("Content-Type")) w.Header().Set("Content-Type", "application/json") - json.NewEncoder(w).Encode(map[string]any{ + _ = json.NewEncoder(w).Encode(map[string]any{ "choices": []map[string]any{ {"message": map[string]any{"role": "assistant", "content": response}}, }, @@ -51,7 +51,7 @@ func TestClient_SendsAuthHeader(t *testing.T) { var gotAuth string srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { gotAuth = r.Header.Get("Authorization") - json.NewEncoder(w).Encode(map[string]any{ + _ = json.NewEncoder(w).Encode(map[string]any{ "choices": []map[string]any{{"message": map[string]any{"content": "ok"}}}, }) })) @@ -72,7 +72,7 @@ func TestClient_Retries429(t *testing.T) { w.WriteHeader(http.StatusTooManyRequests) return } - json.NewEncoder(w).Encode(map[string]any{ + _ = json.NewEncoder(w).Encode(map[string]any{ "choices": []map[string]any{{"message": map[string]any{"content": "retried"}}}, }) })) diff --git a/ingestion/internal/pipeline/pipeline_test.go b/ingestion/internal/pipeline/pipeline_test.go index ac39b3d..e1b8731 100644 --- a/ingestion/internal/pipeline/pipeline_test.go +++ b/ingestion/internal/pipeline/pipeline_test.go @@ -37,7 +37,7 @@ func TestRun_WritesPages(t *testing.T) { srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") - json.NewEncoder(w).Encode(map[string]any{ + _ = json.NewEncoder(w).Encode(map[string]any{ "choices": []map[string]any{ {"message": map[string]any{"role": "assistant", "content": llmResponse}}, }, @@ -77,7 +77,7 @@ func TestRun_DryRunDoesNotWrite(t *testing.T) { }}) srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - json.NewEncoder(w).Encode(map[string]any{ + _ = json.NewEncoder(w).Encode(map[string]any{ "choices": []map[string]any{{"message": map[string]any{"content": llmResponse}}}, }) })) @@ -105,7 +105,7 @@ func TestRun_MergesDuplicatePaths(t *testing.T) { }) srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - json.NewEncoder(w).Encode(map[string]any{ + _ = json.NewEncoder(w).Encode(map[string]any{ "choices": []map[string]any{{"message": map[string]any{"content": llmResponse}}}, }) })) diff --git a/ingestion/internal/watcher/watcher.go b/ingestion/internal/watcher/watcher.go index 46e8407..054552b 100644 --- a/ingestion/internal/watcher/watcher.go +++ b/ingestion/internal/watcher/watcher.go @@ -158,15 +158,15 @@ func copyFile(src, dst string) error { if err != nil { return fmt.Errorf("open src: %w", err) } - defer in.Close() + defer in.Close() //nolint:errcheck out, err := os.Create(dst) if err != nil { return fmt.Errorf("create dst: %w", err) } - defer out.Close() if _, err := io.Copy(out, in); err != nil { + out.Close() //nolint:errcheck return fmt.Errorf("copy: %w", err) } return out.Close() @@ -201,10 +201,10 @@ func appendWatcherLog(brainDir, filename string, runErr error, date string) erro if err != nil { return fmt.Errorf("open log: %w", err) } - defer f.Close() if _, err = f.WriteString(entry); err != nil { + f.Close() //nolint:errcheck return fmt.Errorf("write log: %w", err) } - return nil + return f.Close() } diff --git a/ingestion/internal/wiki/inventory.go b/ingestion/internal/wiki/inventory.go index d887d48..0d83c31 100644 --- a/ingestion/internal/wiki/inventory.go +++ b/ingestion/internal/wiki/inventory.go @@ -47,7 +47,7 @@ func readFrontmatter(path, fallbackSlug string) (title string, aliases []string) if err != nil { return } - defer f.Close() + defer f.Close() //nolint:errcheck scanner := bufio.NewScanner(f) inFM := false diff --git a/ingestion/internal/wiki/log.go b/ingestion/internal/wiki/log.go index ade924c..1b19ae8 100644 --- a/ingestion/internal/wiki/log.go +++ b/ingestion/internal/wiki/log.go @@ -32,9 +32,9 @@ func AppendLog(brainDir, source string, pages, warnings []string, date string) e if err != nil { return fmt.Errorf("open log: %w", err) } - defer f.Close() if _, err = f.WriteString(sb.String()); err != nil { + f.Close() //nolint:errcheck return fmt.Errorf("write log: %w", err) } - return nil + return f.Close() }