fix(ingestion): consistent error handling in search walk

Both walk-level errors and ReadFile failures now use best-effort
semantics (warn via slog, continue) instead of mixed abort/silent-skip.
filepath.Rel error is now propagated from the callback instead of
discarded.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Mathias Bergqvist
2026-04-17 20:23:03 +02:00
parent 3c1f6edf3e
commit caf18c9acb

View File

@@ -3,6 +3,8 @@ package search
import (
"bufio"
"fmt"
"log/slog"
"os"
"path/filepath"
"sort"
@@ -32,13 +34,18 @@ func Query(brainDir, query string, limit int) ([]Result, error) {
var results []Result
err := filepath.WalkDir(filepath.Join(brainDir, "wiki"), func(path string, d os.DirEntry, err error) error {
if err != nil || d.IsDir() || !strings.HasSuffix(path, ".md") {
return err
if err != nil {
slog.Warn("search: skipping path", "path", path, "err", err)
return nil
}
if d.IsDir() || !strings.HasSuffix(path, ".md") {
return nil
}
content, err := os.ReadFile(path)
if err != nil {
return nil // skip unreadable files
slog.Warn("search: skipping unreadable file", "path", path, "err", err)
return nil
}
lower := strings.ToLower(string(content))
@@ -50,7 +57,10 @@ func Query(brainDir, query string, limit int) ([]Result, error) {
return nil
}
rel, _ := filepath.Rel(brainDir, path)
rel, err := filepath.Rel(brainDir, path)
if err != nil {
return fmt.Errorf("rel path: %w", err)
}
rel = filepath.ToSlash(rel)
results = append(results, Result{