Skip to content

Commit 16dc092

Browse files
authored
fix(node): Local variables skipped after Promise (v7) (#11248)
Backport of #11234
1 parent ef37773 commit 16dc092

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

dev-packages/node-integration-tests/suites/public-api/LocalVariables/local-variables-caught.mjs

+8-6
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ Sentry.init({
99
});
1010

1111
class Some {
12-
two(name) {
13-
throw new Error('Enough!');
12+
async two(name) {
13+
return new Promise((_, reject) => {
14+
reject(new Error('Enough!'));
15+
});
1416
}
1517
}
1618

17-
function one(name) {
19+
async function one(name) {
1820
const arr = [1, '2', null];
1921
const obj = {
2022
name,
@@ -28,12 +30,12 @@ function one(name) {
2830

2931
const ty = new Some();
3032

31-
ty.two(name);
33+
await ty.two(name);
3234
}
3335

34-
setTimeout(() => {
36+
setTimeout(async () => {
3537
try {
36-
one('some name');
38+
await one('some name');
3739
} catch (e) {
3840
Sentry.captureException(e);
3941
}

packages/node/src/integrations/local-variables/local-variables-sync.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -296,29 +296,31 @@ const _localVariablesSyncIntegration = ((
296296
return;
297297
}
298298

299-
const frameCount = exception.stacktrace?.frames?.length || 0;
299+
// Filter out frames where the function name is `new Promise` since these are in the error.stack frames
300+
// but do not appear in the debugger call frames
301+
const frames = (exception.stacktrace?.frames || []).filter(frame => frame.function !== 'new Promise');
300302

301-
for (let i = 0; i < frameCount; i++) {
303+
for (let i = 0; i < frames.length; i++) {
302304
// Sentry frames are in reverse order
303-
const frameIndex = frameCount - i - 1;
305+
const frameIndex = frames.length - i - 1;
304306

305307
// Drop out if we run out of frames to match up
306-
if (!exception?.stacktrace?.frames?.[frameIndex] || !cachedFrame[i]) {
308+
if (!frames[frameIndex] || !cachedFrame[i]) {
307309
break;
308310
}
309311

310312
if (
311313
// We need to have vars to add
312314
cachedFrame[i].vars === undefined ||
313315
// We're not interested in frames that are not in_app because the vars are not relevant
314-
exception.stacktrace.frames[frameIndex].in_app === false ||
316+
frames[frameIndex].in_app === false ||
315317
// The function names need to match
316-
!functionNamesMatch(exception.stacktrace.frames[frameIndex].function, cachedFrame[i].function)
318+
!functionNamesMatch(frames[frameIndex].function, cachedFrame[i].function)
317319
) {
318320
continue;
319321
}
320322

321-
exception.stacktrace.frames[frameIndex].vars = cachedFrame[i].vars;
323+
frames[frameIndex].vars = cachedFrame[i].vars;
322324
}
323325
}
324326

0 commit comments

Comments
 (0)