123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- import { node } from './node-stack-trace.js';
- export { filenameIsInApp } from './node-stack-trace.js';
- const STACKTRACE_FRAME_LIMIT = 50;
- const WEBPACK_ERROR_REGEXP = /\(error: (.*)\)/;
- const STRIP_FRAME_REGEXP = /captureMessage|captureException/;
- function createStackParser(...parsers) {
- const sortedParsers = parsers.sort((a, b) => a[0] - b[0]).map(p => p[1]);
- return (stack, skipFirst = 0) => {
- const frames = [];
- const lines = stack.split('\n');
- for (let i = skipFirst; i < lines.length; i++) {
- const line = lines[i];
-
-
-
-
- if (line.length > 1024) {
- continue;
- }
-
-
- const cleanedLine = WEBPACK_ERROR_REGEXP.test(line) ? line.replace(WEBPACK_ERROR_REGEXP, '$1') : line;
-
-
- if (cleanedLine.match(/\S*Error: /)) {
- continue;
- }
- for (const parser of sortedParsers) {
- const frame = parser(cleanedLine);
- if (frame) {
- frames.push(frame);
- break;
- }
- }
- if (frames.length >= STACKTRACE_FRAME_LIMIT) {
- break;
- }
- }
- return stripSentryFramesAndReverse(frames);
- };
- }
- function stackParserFromStackParserOptions(stackParser) {
- if (Array.isArray(stackParser)) {
- return createStackParser(...stackParser);
- }
- return stackParser;
- }
- function stripSentryFramesAndReverse(stack) {
- if (!stack.length) {
- return [];
- }
- const localStack = Array.from(stack);
-
- if (/sentryWrapped/.test(localStack[localStack.length - 1].function || '')) {
- localStack.pop();
- }
-
- localStack.reverse();
-
- if (STRIP_FRAME_REGEXP.test(localStack[localStack.length - 1].function || '')) {
- localStack.pop();
-
-
-
-
-
-
-
-
- if (STRIP_FRAME_REGEXP.test(localStack[localStack.length - 1].function || '')) {
- localStack.pop();
- }
- }
- return localStack.slice(0, STACKTRACE_FRAME_LIMIT).map(frame => ({
- ...frame,
- filename: frame.filename || localStack[localStack.length - 1].filename,
- function: frame.function || '?',
- }));
- }
- const defaultFunctionName = '<anonymous>';
- /**
- * Safely extract function name from itself
- */
- function getFunctionName(fn) {
- try {
- if (!fn || typeof fn !== 'function') {
- return defaultFunctionName;
- }
- return fn.name || defaultFunctionName;
- } catch (e) {
-
-
- return defaultFunctionName;
- }
- }
- function nodeStackLineParser(getModule) {
- return [90, node(getModule)];
- }
- export { createStackParser, getFunctionName, nodeStackLineParser, stackParserFromStackParserOptions, stripSentryFramesAndReverse };
|