Skip to content

fix(utils): Don't attach context lines to stack frames without line number #6549

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions packages/utils/src/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,13 @@ export function parseSemver(input: string): SemVer {
* @param linesOfContext number of context lines we want to add pre/post
*/
export function addContextToFrame(lines: string[], frame: StackFrame, linesOfContext: number = 5): void {
const lineno = frame.lineno || 0;
// When there is no line number in the frame, attaching context is nonsensical and will even break grouping
if (frame.lineno === undefined) {
return;
}

const maxLines = lines.length;
const sourceLine = Math.max(Math.min(maxLines, lineno - 1), 0);
const sourceLine = Math.max(Math.min(maxLines, frame.lineno - 1), 0);

frame.pre_context = lines
.slice(Math.max(0, sourceLine - linesOfContext), sourceLine)
Expand Down