( content: string, )
| 515 | // Error object, so we have to regexp out the message from the stack string |
| 516 | // to format it. |
| 517 | export 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 | }; |
no test coverage detected