Skip to content

feat: parse stack traces and display file/line context (closes #81) - #99

Merged
naheel0 merged 2 commits into
BeyteFlow:mainfrom
naheel0:feat/stack-trace-context
Aug 10, 2026
Merged

naheel0 merged 2 commits into
BeyteFlow:mainfrom
naheel0:feat/stack-trace-context

Conversation

@naheel0

@naheel0 naheel0 commented Aug 10, 2026

Copy link
Copy Markdown
Member

What

Adds stack-trace parsing and file/line context display to errlens, closing #81.

Changes

  • lib/stack-parser.js (new): parseStackTrace() extracts function, file, line, and column from Node-style stack frames; sourceSnippet(filepath, line, radius=2) reads a safe context sample with clamping and internal-frame/file-URL filtering
  • lib/formatter.js: renders a 📍 LOCATION block (first application frame, skipping
    ode:internal\ frames) and a 5-line 📍 CONTEXT snippet when --context\ is enabled
  • bin/index.js: new --context\ option; stack traces parsed in both
    un\ and \�nalyze; \locations\ array added to JSON output
  • test/test-stack.js (new): 31 assertions covering function frames, bare frames, async frames, file:// URLs, empty input, and snippet clamping/edge cases — all passing
  • README.md: docs for --context, the \locations\ JSON field, and stack-trace parsing

Acceptance criteria

  • Input with a stack trace prints the location and a 5-line snippet (--context)
  • JSON output includes a \locations\ array with frame details

Notes

  • Existing --json, --theme, --verbose, and --lang\ behavior is unchanged
  • Source snippets are only rendered when the target file exists and is readable

Summary by CodeRabbit

  • New Features

    • Added stack-trace parsing to identify error locations.
    • Added optional source-code context around reported error lines with --context.
    • JSON output now includes parsed error locations.
    • Error messages highlight the relevant stack frame and source line when available.
  • Documentation

    • Added usage examples and reference information for stack locations, filtering, and source snippets.

- Add lib/stack-parser.js with parseStackTrace() to extract function, file, line, column from Node-style stack frames and sourceSnippet() to read a safe context sample around a location
- Update lib/formatter.js to render a LOCATION block (picks the first application frame, skipping node:internal frames) and a 5-line CONTEXT snippet when --context is enabled
- Update bin/index.js: add --context option; parse stack traces in both run and analyze; pass locations to the formatter and expose them in JSON output
- Add test/test-stack.js covering common Node stack formats (function frames, bare frames, async frames, file:// URLs) and snippet clamping/edge cases
- Update README with stack-trace parsing docs and JSON locations example
@naheel0
naheel0 requested a review from jaseel0 as a code owner August 10, 2026 10:00
@github-actions github-actions Bot added documentation Improvements or additions to documentation core cli testing labels Aug 10, 2026
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@naheel0, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 53 seconds

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 07234b63-9d54-4644-ae86-5075a7a85458

📥 Commits

Reviewing files that changed from the base of the PR and between b7124fd and 8b67f0d.

📒 Files selected for processing (3)
  • README.md
  • lib/stack-parser.js
  • test/test-stack.js
📝 Walkthrough

Walkthrough

The CLI now parses stack traces into structured locations, includes them in JSON output, and supports optional source snippets through --context. Formatted errors select an application frame and display nearby source lines. The README and tests document and validate the behavior.

Changes

Stack trace context

Layer / File(s) Summary
Stack parsing and source inspection
lib/stack-parser.js, test/test-stack.js
The new helpers parse Node-style frames, identify internal frames, and extract bounded source snippets. Tests cover supported formats, invalid input, file errors, and snippet markers.
CLI output and formatted context
bin/index.js, lib/formatter.js
run and analyze now expose parsed locations in JSON output and pass --context settings to formatting. Formatted errors show the selected application frame and optional source context.
Usage and output documentation
README.md
The README documents stack locations, --context, source snippets, frame filtering, and JSON output.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related issues

Possibly related PRs

  • BeyteFlow/errlens#96 — Both changes update the CLI and formatter flow, including related output options.

Suggested reviewers: jaseel0

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant StackParser
  participant Formatter
  participant SourceFile
  CLI->>StackParser: Parse error stack
  StackParser-->>CLI: Return locations
  CLI->>Formatter: Format error with locations and context option
  Formatter->>SourceFile: Read selected application frame
  SourceFile-->>Formatter: Return source snippet
  Formatter-->>CLI: Return formatted output
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main changes: stack-trace parsing and file/line context display.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@naheel0

naheel0 commented Aug 10, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@lib/stack-parser.js`:
- Around line 64-76: Update sourceSnippet in lib/stack-parser.js around the
fileURLToPath/readFileSync flow to canonicalize stack-derived paths, allow only
approved source roots, and reject symlink escapes, non-regular files, and files
exceeding a defined size limit before reading; return null for rejected paths.
Add corresponding test cases in test/test-stack.js for an outside-root file URL,
symlink escape, and non-regular file, each asserting null. Update README.md at
the documented --context behavior to describe the selected file:// path policy.

In `@README.md`:
- Around line 195-206: Add the locations field with an empty array to the
earlier normal run --json example in README.md, matching bin/index.js output and
the existing stack-frame schema while leaving the error example unchanged.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 1c0e7570-82dd-4973-b595-a39cf15f0379

📥 Commits

Reviewing files that changed from the base of the PR and between 4465ede and b7124fd.

📒 Files selected for processing (5)
  • README.md
  • bin/index.js
  • lib/formatter.js
  • lib/stack-parser.js
  • test/test-stack.js

Comment thread lib/stack-parser.js
Comment thread README.md
- lib/stack-parser.js: constrain sourceSnippet to approved source root (cwd); decode only regular files, reject paths outside the root, symlink escapes, non-regular files, and files over 256 KiB. Fix parseFrame to split function/location using balanced-paren matching so Windows paths containing parentheses (e.g. 'Work (copy)') parse correctly
- test/test-stack.js: add tests for outside-root path, outside-root file URL, symlink escape, non-regular file, and oversized file (all null); add regression test for parens in file paths
- README.md: document the --context source-path policy and add locations:[] to the run --json example
@naheel0

naheel0 commented Aug 10, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@naheel0
naheel0 merged commit 055a1bf into BeyteFlow:main Aug 10, 2026
5 checks passed
@naheel0
naheel0 deleted the feat/stack-trace-context branch August 10, 2026 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli core documentation Improvements or additions to documentation testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant