MCPcopy Index your code
hub / github.com/getsentry/sentry-javascript / addContextToFrame

Function addContextToFrame

packages/core/src/utils/misc.ts:169–191  ·  view source on GitHub ↗
(lines: string[], frame: StackFrame, linesOfContext: number = 5)

Source from the content-addressed store, hash-verified

167 * @param linesOfContext number of context lines we want to add pre/post
168 */
169export function addContextToFrame(lines: string[], frame: StackFrame, linesOfContext: number = 5): void {
170 // When there is no line number in the frame, attaching context is nonsensical and will even break grouping
171 if (frame.lineno === undefined) {
172 return;
173 }
174
175 const maxLines = lines.length;
176 const sourceLine = Math.max(Math.min(maxLines - 1, frame.lineno - 1), 0);
177
178 frame.pre_context = lines
179 .slice(Math.max(0, sourceLine - linesOfContext), sourceLine)
180 .map((line: string) => snipLine(line, 0));
181
182 // We guard here to ensure this is not larger than the existing number of lines
183 const lineIndex = Math.min(maxLines - 1, sourceLine);
184
185 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
186 frame.context_line = snipLine(lines[lineIndex]!, frame.colno || 0);
187
188 frame.post_context = lines
189 .slice(Math.min(sourceLine + 1, maxLines), sourceLine + 1 + linesOfContext)
190 .map((line: string) => snipLine(line, 0));
191}
192
193/**
194 * Checks whether or not we've already captured the given exception (note: not an identical exception - the very object

Callers 3

misc.test.tsFile · 0.90
addSourceContextToFramesFunction · 0.90

Calls 2

snipLineFunction · 0.90
sliceMethod · 0.80

Tested by

no test coverage detected