fix(ingestion): wrap naked error returns and harden mustJSON helper

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Mathias Bergqvist
2026-04-22 22:51:19 +02:00
parent 103f4d90bf
commit 04fefe8e9c
3 changed files with 10 additions and 4 deletions

View File

@@ -125,6 +125,9 @@ func TestRun_MergesDuplicatePaths(t *testing.T) {
} }
func mustJSON(v any) string { func mustJSON(v any) string {
b, _ := json.Marshal(v) b, err := json.Marshal(v)
if err != nil {
panic(err)
}
return string(b) return string(b)
} }

View File

@@ -3,6 +3,7 @@ package wiki
import ( import (
"bufio" "bufio"
"fmt"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
@@ -23,7 +24,7 @@ func LoadInventory(brainDir string) (map[PageType][]Entry, error) {
continue continue
} }
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("read dir %s: %w", dir, err)
} }
for _, e := range entries { for _, e := range entries {
if e.IsDir() || !strings.HasSuffix(e.Name(), ".md") { if e.IsDir() || !strings.HasSuffix(e.Name(), ".md") {

View File

@@ -33,6 +33,8 @@ func AppendLog(brainDir, source string, pages, warnings []string, date string) e
return fmt.Errorf("open log: %w", err) return fmt.Errorf("open log: %w", err)
} }
defer f.Close() defer f.Close()
_, err = f.WriteString(sb.String()) if _, err = f.WriteString(sb.String()); err != nil {
return err return fmt.Errorf("write log: %w", err)
}
return nil
} }