Skip to content

Commit ffb5511

Browse files
authored
fix(node): account for Object. syntax with local variables matching (#16702)
resolves #16701 For function frames that give us function named `X`, the debugger protocol (which is what local variables use) sometimes outputs `Object.X` as the function name. This causes issues when we try to apply local variables to a stacktrace frame.
1 parent 29d35b4 commit ffb5511

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const Sentry = require('@sentry/node');
2+
const { loggingTransport } = require('@sentry-internal/node-integration-tests');
3+
4+
Sentry.init({
5+
dsn: 'https://public@dsn.ingest.sentry.io/1337',
6+
includeLocalVariables: true,
7+
transport: loggingTransport,
8+
});
9+
10+
process.on('uncaughtException', () => {
11+
// do nothing - this will prevent the Error below from closing this process
12+
});
13+
14+
// Testing GraphQL resolver: https://github.com/getsentry/sentry-javascript/issues/16701
15+
const resolvers = {
16+
Query: {
17+
testSentry: args => {
18+
try {
19+
args.foo.map(x => x);
20+
return true;
21+
} catch (error) {
22+
Sentry.captureException(error);
23+
return false;
24+
}
25+
},
26+
},
27+
};
28+
29+
function regularFunction() {
30+
resolvers.Query.testSentry({ foo: undefined });
31+
}
32+
33+
setTimeout(() => {
34+
regularFunction();
35+
}, 1000);

dev-packages/node-integration-tests/suites/public-api/LocalVariables/test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,30 @@ describe('LocalVariables integration', () => {
101101
.start()
102102
.completed();
103103
});
104+
105+
test('Should handle different function name formats', async () => {
106+
await createRunner(__dirname, 'local-variables-name-matching.js')
107+
.expect({
108+
event: {
109+
exception: {
110+
values: [
111+
{
112+
stacktrace: {
113+
frames: expect.arrayContaining([
114+
expect.objectContaining({
115+
function: expect.stringMatching(/^(Object\.testSentry|testSentry)$/),
116+
vars: expect.objectContaining({
117+
args: expect.any(Object),
118+
}),
119+
}),
120+
]),
121+
},
122+
},
123+
],
124+
},
125+
},
126+
})
127+
.start()
128+
.completed();
129+
});
104130
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export function isAnonymous(name: string | undefined): boolean {
7070

7171
/** Do the function names appear to match? */
7272
export function functionNamesMatch(a: string | undefined, b: string | undefined): boolean {
73-
return a === b || (isAnonymous(a) && isAnonymous(b));
73+
return a === b || `Object.${a}` === b || a === `Object.${b}` || (isAnonymous(a) && isAnonymous(b));
7474
}
7575

7676
export interface FrameVariables {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy