Skip to content

Commit a4593a2

Browse files
committed
silently fail maybeInstrument
1 parent b6dbde8 commit a4593a2

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

packages/utils/src/instrument/handlers.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,12 @@ export function resetInstrumentationHandlers(): void {
3737
/** Maybe run an instrumentation function, unless it was already called. */
3838
export function maybeInstrument(type: InstrumentHandlerType, instrumentFn: () => void): void {
3939
if (!instrumented[type]) {
40-
instrumentFn();
41-
instrumented[type] = true;
40+
try {
41+
instrumentFn();
42+
instrumented[type] = true;
43+
} catch (e) {
44+
DEBUG_BUILD && logger.error('Error while instrumenting', e);
45+
}
4246
}
4347
}
4448

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { maybeInstrument } from '../src';
2+
3+
describe('maybeInstrument', () => {
4+
test('does not throw when instrumenting fails', () => {
5+
maybeInstrument('xhr', () => {
6+
throw new Error('test');
7+
});
8+
});
9+
10+
test('does not throw when instrumenting fn is not a function', () => {
11+
maybeInstrument('xhr', undefined as any);
12+
});
13+
});

0 commit comments

Comments
 (0)