Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
code review changes
  • Loading branch information
timfish committed Mar 2, 2022
commit b9793e47dd27aa9583f36b6520df2bd6313095ac
1 change: 0 additions & 1 deletion packages/browser/src/eventbuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ export function parseStackFrames(ex: Error & { framesToPop?: number; stacktrace?
const popSize = getPopSize(ex);

try {
// The order of the parsers in important
return createStackParser(
opera10StackParser,
opera11StackParser,
Expand Down
16 changes: 11 additions & 5 deletions packages/browser/src/stack-parsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ import { StackLineParser, StackLineParserFn } from '@sentry/utils';
// global reference to slice
const UNKNOWN_FUNCTION = '?';

const OPERA10_PRIORITY = 10;
const OPERA11_PRIORITY = 20;
const CHROME_PRIORITY = 30;
const WINJS_PRIORITY = 40;
const GECKO_PRIORITY = 50;

function createFrame(filename: string, func: string, lineno?: number, colno?: number): StackFrame {
const frame: StackFrame = {
filename,
Expand Down Expand Up @@ -55,7 +61,7 @@ const chrome: StackLineParserFn = line => {
return;
};

export const chromeStackParser: StackLineParser = [30, chrome];
export const chromeStackParser: StackLineParser = [CHROME_PRIORITY, chrome];

// gecko regex: `(?:bundle|\d+\.js)`: `bundle` is for react native, `\d+\.js` also but specifically for ram bundles because it
// generates filenames without a prefix like `file://` the filenames in the stacktrace are just 42.js
Expand Down Expand Up @@ -91,7 +97,7 @@ const gecko: StackLineParserFn = line => {
return;
};

export const geckoStackParser: StackLineParser = [50, gecko];
export const geckoStackParser: StackLineParser = [GECKO_PRIORITY, gecko];

const winjsRegex =
/^\s*at (?:((?:\[object object\])?.+) )?\(?((?:file|ms-appx|https?|webpack|blob):.*?):(\d+)(?::(\d+))?\)?\s*$/i;
Expand All @@ -104,7 +110,7 @@ const winjs: StackLineParserFn = line => {
: undefined;
};

export const winjsStackParser: StackLineParser = [40, winjs];
export const winjsStackParser: StackLineParser = [WINJS_PRIORITY, winjs];

const opera10Regex = / line (\d+).*script (?:in )?(\S+)(?:: in function (\S+))?$/i;

Expand All @@ -113,7 +119,7 @@ const opera10: StackLineParserFn = line => {
return parts ? createFrame(parts[2], parts[3] || UNKNOWN_FUNCTION, +parts[1]) : undefined;
};

export const opera10StackParser: StackLineParser = [10, opera10];
export const opera10StackParser: StackLineParser = [OPERA10_PRIORITY, opera10];

const opera11Regex =
/ line (\d+), column (\d+)\s*(?:in (?:<anonymous function: ([^>]+)>|([^)]+))\(.*\))? in (.*):\s*$/i;
Expand All @@ -123,7 +129,7 @@ const opera11: StackLineParserFn = line => {
return parts ? createFrame(parts[5], parts[3] || parts[4] || UNKNOWN_FUNCTION, +parts[1], +parts[2]) : undefined;
};

export const opera11StackParser: StackLineParser = [20, opera11];
export const opera11StackParser: StackLineParser = [OPERA11_PRIORITY, opera11];

/**
* Safari web extensions, starting version unknown, can produce "frames-only" stacktraces.
Expand Down
3 changes: 2 additions & 1 deletion packages/utils/src/stacktrace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { StackFrame } from '@sentry/types';

const STACKTRACE_LIMIT = 50;

export type StackParser = (stack: string, skipFirst?: number) => StackFrame[];
export type StackLineParserFn = (line: string) => StackFrame | undefined;
export type StackLineParser = [number, StackLineParserFn];

Expand All @@ -12,7 +13,7 @@ export type StackLineParser = [number, StackLineParserFn];
* frames and with Sentry SDK internal frames removed from the top and bottom
*
*/
export function createStackParser(...parsers: StackLineParser[]): (stack: string, skipFirst?: number) => StackFrame[] {
export function createStackParser(...parsers: StackLineParser[]): StackParser {
const sortedParsers = parsers.sort((a, b) => a[0] - b[0]).map(p => p[1]);

return (stack: string, skipFirst: number = 0): StackFrame[] => {
Expand Down