MCPcopy
hub / github.com/vitest-dev/vitest / parseErrorStacktrace

Function parseErrorStacktrace

packages/utils/src/source-map.ts:307–344  ·  view source on GitHub ↗
(
  e: TestError | Error,
  options: StackTraceParserOptions = {},
)

Source from the content-addressed store, hash-verified

305}
306
307export function parseErrorStacktrace(
308 e: TestError | Error,
309 options: StackTraceParserOptions = {},
310): ParsedStack[] {
311 if (!e || isPrimitive(e)) {
312 return []
313 }
314
315 if ('stacks' in e && e.stacks) {
316 return e.stacks
317 }
318
319 const stackStr = e.stack || ''
320 // if "stack" property was overwritten at runtime to be something else,
321 // ignore the value because we don't know how to process it
322 let stackFrames = typeof stackStr === 'string'
323 ? parseStacktrace(stackStr, options)
324 : []
325
326 if (!stackFrames.length) {
327 const e_ = e as any
328 if (e_.fileName != null && e_.lineNumber != null && e_.columnNumber != null) {
329 stackFrames = parseStacktrace(`${e_.fileName}:${e_.lineNumber}:${e_.columnNumber}`, options)
330 }
331 if (e_.sourceURL != null && e_.line != null && e_._column != null) {
332 stackFrames = parseStacktrace(`${e_.sourceURL}:${e_.line}:${e_.column}`, options)
333 }
334 }
335
336 if (options.frameFilter) {
337 stackFrames = stackFrames.filter(
338 f => options.frameFilter!(e as TestError, f) !== false,
339 )
340 }
341
342 ;(e as TestError).stacks = stackFrames
343 return stackFrames
344}
345
346interface SourceMapLike {
347 version: number

Callers 5

parseErrorStacktraceMethod · 0.90
syncUpdateStacksMethod · 0.90
parseErrorStacktraceFunction · 0.90
logTasksMethod · 0.90
_resolveInlineStackMethod · 0.90

Calls 3

isPrimitiveFunction · 0.90
parseStacktraceFunction · 0.85
filterMethod · 0.65

Tested by

no test coverage detected