Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(node): Local variables skipped after Promise (v7) #11248

Merged
merged 1 commit into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ Sentry.init({
});

class Some {
two(name) {
throw new Error('Enough!');
async two(name) {
return new Promise((_, reject) => {
reject(new Error('Enough!'));
});
}
}

function one(name) {
async function one(name) {
const arr = [1, '2', null];
const obj = {
name,
Expand All @@ -28,12 +30,12 @@ function one(name) {

const ty = new Some();

ty.two(name);
await ty.two(name);
}

setTimeout(() => {
setTimeout(async () => {
try {
one('some name');
await one('some name');
} catch (e) {
Sentry.captureException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,29 +296,31 @@ const _localVariablesSyncIntegration = ((
return;
}

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

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

// Drop out if we run out of frames to match up
if (!exception?.stacktrace?.frames?.[frameIndex] || !cachedFrame[i]) {
if (!frames[frameIndex] || !cachedFrame[i]) {
break;
}

if (
// We need to have vars to add
cachedFrame[i].vars === undefined ||
// We're not interested in frames that are not in_app because the vars are not relevant
exception.stacktrace.frames[frameIndex].in_app === false ||
frames[frameIndex].in_app === false ||
// The function names need to match
!functionNamesMatch(exception.stacktrace.frames[frameIndex].function, cachedFrame[i].function)
!functionNamesMatch(frames[frameIndex].function, cachedFrame[i].function)
) {
continue;
}

exception.stacktrace.frames[frameIndex].vars = cachedFrame[i].vars;
frames[frameIndex].vars = cachedFrame[i].vars;
}
}

Expand Down
Loading