Skip to content

Commit 6c22fa5

Browse files
committed
Always use ? for anonymous function name
1 parent b92d422 commit 6c22fa5

File tree

6 files changed

+19
-19
lines changed

6 files changed

+19
-19
lines changed

packages/browser/src/integrations/globalhandlers.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
isPrimitive,
1010
isString,
1111
logger,
12+
UNKNOWN_FUNCTION,
1213
} from '@sentry/utils';
1314

1415
import { BrowserClient } from '../client';
@@ -227,7 +228,7 @@ function _enhanceEventWithInitialFrame(event: Event, url: any, line: any, column
227228
ev0sf.push({
228229
colno,
229230
filename,
230-
function: '?',
231+
function: UNKNOWN_FUNCTION,
231232
in_app: true,
232233
lineno,
233234
});

packages/browser/src/stack-parsers.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import { StackFrame, StackLineParser, StackLineParserFn } from '@sentry/types';
2-
import { createStackParser } from '@sentry/utils';
3-
4-
// global reference to slice
5-
const UNKNOWN_FUNCTION = '?';
2+
import { createStackParser, UNKNOWN_FUNCTION } from '@sentry/utils';
63

74
const OPERA10_PRIORITY = 10;
85
const OPERA11_PRIORITY = 20;

packages/integrations/src/transaction.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Event, EventProcessor, Hub, Integration, StackFrame } from '@sentry/types';
2+
import { UNKNOWN_FUNCTION } from '@sentry/utils';
23

34
/** Add node transaction to the event */
45
export class Transaction implements Integration {
@@ -52,6 +53,8 @@ export class Transaction implements Integration {
5253

5354
/** JSDoc */
5455
private _getTransaction(frame: StackFrame): string {
55-
return frame.module || frame.function ? `${frame.module || '?'}/${frame.function || '?'}` : '<unknown>';
56+
return frame.module || frame.function
57+
? `${frame.module || UNKNOWN_FUNCTION}/${frame.function || UNKNOWN_FUNCTION}`
58+
: '<unknown>';
5659
}
5760
}

packages/node/test/stacktrace.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ describe('Stack parsing', () => {
192192
{
193193
filename: '/Users/felix/code/node-fast-or-slow/lib/test_case.js',
194194
module: 'test_case',
195-
function: '<anonymous>',
195+
function: '?',
196196
lineno: 80,
197197
colno: 10,
198198
in_app: true,
@@ -212,7 +212,7 @@ describe('Stack parsing', () => {
212212
{
213213
filename: '/Users/felix/code/node-fast-or-slow/lib/test_case.js',
214214
module: 'test_case',
215-
function: '<anonymous>',
215+
function: '?',
216216
lineno: 80,
217217
colno: 10,
218218
in_app: true,
@@ -289,7 +289,7 @@ describe('Stack parsing', () => {
289289
{
290290
filename: '/code/node_modules/kafkajs/src/consumer/runner.js',
291291
module: 'kafkajs.src.consumer:runner',
292-
function: '<anonymous>',
292+
function: '?',
293293
lineno: 376,
294294
colno: 15,
295295
in_app: false,

packages/utils/src/stacktrace.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { StackFrame, StackLineParser, StackLineParserFn, StackParser } from '@sentry/types';
22

33
const STACKTRACE_LIMIT = 50;
4+
export const UNKNOWN_FUNCTION = '?';
45

56
/**
67
* Creates a stack parser with the supplied line parsers
@@ -76,26 +77,24 @@ export function stripSentryFramesAndReverse(stack: StackFrame[]): StackFrame[] {
7677
.map(frame => ({
7778
...frame,
7879
filename: frame.filename || localStack[0].filename,
79-
function: frame.function || '?',
80+
function: frame.function || UNKNOWN_FUNCTION,
8081
}))
8182
.reverse();
8283
}
8384

84-
const defaultFunctionName = '<anonymous>';
85-
8685
/**
8786
* Safely extract function name from itself
8887
*/
8988
export function getFunctionName(fn: unknown): string {
9089
try {
9190
if (!fn || typeof fn !== 'function') {
92-
return defaultFunctionName;
91+
return UNKNOWN_FUNCTION;
9392
}
94-
return fn.name || defaultFunctionName;
93+
return fn.name || UNKNOWN_FUNCTION;
9594
} catch (e) {
9695
// Just accessing custom props in some Selenium environments
9796
// can cause a "Permission denied" exception (see raven-js#495).
98-
return defaultFunctionName;
97+
return UNKNOWN_FUNCTION;
9998
}
10099
}
101100

@@ -151,13 +150,13 @@ function node(getModule?: GetModuleFn): StackLineParserFn {
151150
methodName = method;
152151
}
153152

154-
if (method === '<anonymous>') {
153+
if (method === UNKNOWN_FUNCTION) {
155154
methodName = undefined;
156155
functionName = undefined;
157156
}
158157

159158
if (functionName === undefined) {
160-
methodName = methodName || '<anonymous>';
159+
methodName = methodName || UNKNOWN_FUNCTION;
161160
functionName = typeName ? `${typeName}.${methodName}` : methodName;
162161
}
163162

packages/utils/test/normalize.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ describe('normalize()', () => {
291291
subject.toJSON = () => {
292292
throw new Error("I'm faulty!");
293293
};
294-
expect(normalize(subject)).toEqual({ a: 1, foo: 'bar', toJSON: '[Function: <anonymous>]' });
294+
expect(normalize(subject)).toEqual({ a: 1, foo: 'bar', toJSON: '[Function: ?]' });
295295
});
296296

297297
test('should return an object without circular references when toJSON returns an object with circular references', () => {
@@ -327,7 +327,7 @@ describe('normalize()', () => {
327327
normalize(() => {
328328
/* no-empty */
329329
}),
330-
).toEqual('[Function: <anonymous>]');
330+
).toEqual('[Function: ?]');
331331
const foo = () => {
332332
/* no-empty */
333333
};

0 commit comments

Comments
 (0)