MCPcopy Index your code
hub / github.com/getsentry/sentry-javascript / patchFrames

Function patchFrames

packages/wasm/src/index.ts:86–138  ·  view source on GitHub ↗
(
  frames: Array<StackFrame>,
  applicationKey?: string,
  existingImagesOffset: number = 0,
)

Source from the content-addressed store, hash-verified

84 */
85// Only exported for tests
86export function patchFrames(
87 frames: Array<StackFrame>,
88 applicationKey?: string,
89 existingImagesOffset: number = 0,
90): boolean {
91 let hasAtLeastOneWasmFrameWithImage = false;
92 frames.forEach(frame => {
93 if (!frame.filename) {
94 return;
95 }
96
97 const split = frame.filename.split('(');
98 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
99 const lastSplit = split[split.length - 1]!;
100
101 // Let's call this first match a "messy match".
102 // The browser stacktrace parser spits out frames that have a filename like this: "int) const (http://localhost:8001/main.wasm:wasm-function[190]:0x5aeb"
103 // It contains some leftover mess because wasm stack frames are more complicated than our parser can handle: "at MyClass::bar(int) const (http://localhost:8001/main.wasm:wasm-function[190]:0x5aeb)"
104 // This first match simply tries to mitigate the mess up until the first opening parens.
105 // The match afterwards is a sensible fallback
106 let match = lastSplit.match(PARSER_REGEX) as null | [string, string, string];
107
108 if (!match) {
109 match = frame.filename.match(PARSER_REGEX) as null | [string, string, string];
110 }
111
112 if (match) {
113 const index = getImage(match[1]);
114 const workerImageIndex = getWorkerImage(match[1]);
115 frame.instruction_addr = match[2];
116 frame.filename = match[1];
117 frame.platform = 'native';
118
119 if (applicationKey) {
120 frame.module_metadata = {
121 ...frame.module_metadata,
122 [`${BUNDLER_PLUGIN_APP_KEY_PREFIX}${applicationKey}`]: true,
123 };
124 }
125
126 if (index >= 0) {
127 frame.addr_mode = `rel:${existingImagesOffset + index}`;
128 hasAtLeastOneWasmFrameWithImage = true;
129 } else if (workerImageIndex >= 0) {
130 const mainThreadImagesCount = getImages().length;
131 frame.addr_mode = `rel:${existingImagesOffset + mainThreadImagesCount + workerImageIndex}`;
132 hasAtLeastOneWasmFrameWithImage = true;
133 }
134 }
135 });
136
137 return hasAtLeastOneWasmFrameWithImage;
138}
139
140/**
141 * Looks up an image by URL in worker images.

Callers 3

webworker.test.tsFile · 0.90
processEventFunction · 0.85

Calls 5

getImageFunction · 0.90
getImagesFunction · 0.90
getWorkerImageFunction · 0.85
matchMethod · 0.80
forEachMethod · 0.65

Tested by

no test coverage detected