(error: Error)
| 25 | * to Google Analytics. |
| 26 | */ |
| 27 | export function formatErrorForAnalytics(error: Error): string { |
| 28 | let stack = '<no-stack>'; |
| 29 | |
| 30 | if (error.stack) { |
| 31 | stack = stripErrorMessagePrefix(error.stack) |
| 32 | // strip the message from the stack trace, if present |
| 33 | .replace(error.message + '\n', '') |
| 34 | // strip leading spaces |
| 35 | .replace(/^ +/gm, '') |
| 36 | // strip all leading "at " for each frame |
| 37 | .replace(/^at /gm, '') |
| 38 | // replace long urls with just the last segment: `filename:line:column` |
| 39 | .replace(/(?: \(|@)http.+\/([^/)]+)\)?(?:\n|$)/gm, '@$1\n') |
| 40 | // replace "eval code" in Edge |
| 41 | .replace(/ *\(eval code(:\d+:\d+)\)(?:\n|$)/gm, '@???$1\n'); |
| 42 | } |
| 43 | |
| 44 | return `${error.message}\n${stack}`; |
| 45 | } |
| 46 | |
| 47 | /** Strips the error message prefix from a message or stack trace. */ |
| 48 | function stripErrorMessagePrefix(input: string): string { |
no test coverage detected