feat: parse stack traces and display file/line context (closes #81) - #99
Conversation
- 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
|
Warning Review limit reached
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 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 configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThe CLI now parses stack traces into structured locations, includes them in JSON output, and supports optional source snippets through ChangesStack trace context
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related issues
Possibly related PRs
Suggested reviewers: 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
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
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
📒 Files selected for processing (5)
README.mdbin/index.jslib/formatter.jslib/stack-parser.jstest/test-stack.js
- 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
|
@coderabbitai review |
|
What
Adds stack-trace parsing and file/line context display to errlens, closing #81.
Changes
ode:internal\ frames) and a 5-line 📍 CONTEXT snippet when --context\ is enabled
un\ and \�nalyze; \locations\ array added to JSON output
Acceptance criteria
Notes
Summary by CodeRabbit
New Features
--context.Documentation