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:
@@ -3,6 +3,8 @@ package search
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"fmt"
|
||||||
|
"log/slog"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
@@ -32,13 +34,18 @@ func Query(brainDir, query string, limit int) ([]Result, error) {
|
|||||||
var results []Result
|
var results []Result
|
||||||
|
|
||||||
err := filepath.WalkDir(filepath.Join(brainDir, "wiki"), func(path string, d os.DirEntry, err error) error {
|
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") {
|
if err != nil {
|
||||||
return err
|
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)
|
content, err := os.ReadFile(path)
|
||||||
if err != nil {
|
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))
|
lower := strings.ToLower(string(content))
|
||||||
@@ -50,7 +57,10 @@ func Query(brainDir, query string, limit int) ([]Result, error) {
|
|||||||
return nil
|
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)
|
rel = filepath.ToSlash(rel)
|
||||||
|
|
||||||
results = append(results, Result{
|
results = append(results, Result{
|
||||||
|
|||||||
Reference in New Issue
Block a user