MCPcopy
hub / github.com/jestjs/jest / separateMessageFromStack

Function separateMessageFromStack

packages/jest-message-util/src/index.ts:517–538  ·  view source on GitHub ↗
(
  content: string,
)

Source from the content-addressed store, hash-verified

515// Error object, so we have to regexp out the message from the stack string
516// to format it.
517export const separateMessageFromStack = (
518 content: string,
519): {message: string; stack: string} => {
520 if (!content) {
521 return {message: '', stack: ''};
522 }
523
524 // All lines up to what looks like a stack -- or if nothing looks like a stack
525 // (maybe it's a code frame instead), just the first non-empty line.
526 // If the error is a plain "Error:" instead of a SyntaxError or TypeError we
527 // remove the prefix from the message because it is generally not useful.
528 const messageMatch = content.match(
529 /^(?:Error: )?([\S\s]*?(?=\n\s*at\s.*:\d*:\d*)|\s*.*)([\S\s]*)$/,
530 );
531 if (!messageMatch) {
532 // For typescript
533 throw new Error('If you hit this error, the regex above is buggy.');
534 }
535 const message = removeBlankErrorLine(messageMatch[1]);
536 const stack = removeBlankErrorLine(messageMatch[2]);
537 return {message, stack};
538};

Callers 8

strToErrorFunction · 0.90
formatStackFunction · 0.90
printTestFileHeaderMethod · 0.90
#getMessageDetailsMethod · 0.90
formatErrorFunction · 0.90
formatExecErrorFunction · 0.85
formatErrorStackFunction · 0.85

Calls 2

removeBlankErrorLineFunction · 0.85
matchMethod · 0.80

Tested by

no test coverage detected