fix(buglog): make `bug search` null-safe across schema drift
Problem
openwolf bug search <term> crashes with a TypeError on any buglog that contains an entry missing one of the fields searchBugs assumes are always present:
TypeError: Cannot read properties of undefined (reading 'toLowerCase')
at .../dist/src/buglog/bug-tracker.js:79 // b.file.toLowerCase()
searchBugs does b.error_message.toLowerCase(), b.tags.some(...), b.file.toLowerCase() etc. with no null-guard. Real-world buglogs drift over time:
- Older entries omit
fileand/ortags. - Some tooling records a
files: string[]array instead of a singularfile.
A single such entry anywhere in the array makes the .filter() callback throw, which aborts the entire search — so one legacy entry breaks bug search for the whole project. (Hit this on a 1900+ entry buglog where ~28 audit-finding-* entries had no file key.)
Fix
Make the search field-access null-safe and tolerant of the files array:
- A
has(s)helper (typeof s === "string" && …) andhasAny(a)(Array.isArray(a) && a.some(has)) so a missing/wrong-typed field on one entry skips that entry instead of crashing the whole search. - Also search the
filesarray; addedfiles?: string[]toBugEntryand madefileoptional to match real-world data.
No behavioural change for well-formed entries; only previously-crashing inputs now search cleanly.
Verification
pnpm exec tsc --noEmit→ 0 errors.- Functional test over a mixed-schema buglog (one entry missing
file, one with afilesarray, one normal):search "legacy"→ matches the missing-fileentry (previously crashed) ✓search "<a files path>"→ matches via thefilesarray ✓search "<a file path>"→ matches via singularfile✓
🤖 Generated with Claude Code