Skip to content

fix(buglog): make bug search null-safe across schema drift#44

Open
GordongWang wants to merge 1 commit into
cytostack:mainfrom
GordongWang:fix/searchbugs-null-safe-schema-drift
Open

fix(buglog): make bug search null-safe across schema drift#44
GordongWang wants to merge 1 commit into
cytostack:mainfrom
GordongWang:fix/searchbugs-null-safe-schema-drift

Conversation

@GordongWang

Copy link
Copy Markdown

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 file and/or tags.
  • Some tooling records a files: string[] array instead of a singular file.

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" && …) and hasAny(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 files array; added files?: string[] to BugEntry and made file optional to match real-world data.

No behavioural change for well-formed entries; only previously-crashing inputs now search cleanly.

Verification

  • pnpm exec tsc --noEmit0 errors.
  • Functional test over a mixed-schema buglog (one entry missing file, one with a files array, one normal):
    • search "legacy" → matches the missing-file entry (previously crashed) ✓
    • search "<a files path>" → matches via the files array
    • search "<a file path>" → matches via singular file

🤖 Generated with Claude Code

searchBugs assumed every entry has non-null error_message/root_cause/fix/
tags/file. A single entry missing any of these (older entries omit file/
tags; some tooling writes a `files` array instead of singular `file`)
made b.file.toLowerCase() / b.tags.some() throw, aborting the ENTIRE search.

- Guard every field access (typeof string / Array.isArray) so a missing
  field on one entry skips it instead of crashing the whole search.
- Also search the `files` array (added files?: string[] to BugEntry) and
  make `file` optional to match real-world buglogs.

Verified: tsc --noEmit 0 errors; functional test over a mixed-schema buglog
(missing file / files array / normal) — no crash, correct matches.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant