Skip to content

bug(embedder): extractLeadingComment crashes on out-of-bounds line access #114

@carlos-alm

Description

@carlos-alm

Found during dogfooding v2.4.0

Severity: Medium
Command: codegraph embed -m minilm --strategy structured

Reproduction

  1. Build a graph: codegraph build .
  2. Switch to a branch where some files were renamed/deleted (stale node data)
  3. Run: codegraph embed -m minilm --strategy structured

Expected behavior

Should gracefully skip symbols with invalid line numbers.

Actual behavior

TypeError: Cannot read properties of undefined (reading 'trim')
    at extractLeadingComment (embedder.js:138:30)
    at buildStructuredText (embedder.js:200:19)

Root cause

extractLeadingComment(lines, fnLineIndex) doesn't bounds-check lines[i]. When fnLineIndex > lines.length (stale graph data), lines[i] is undefined.

Suggested fix

Add bounds check at the top of the loop in extractLeadingComment:

if (i >= lines.length) continue;

Or clamp fnLineIndex to lines.length before starting the loop.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdogfoodFound during dogfooding

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions