Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 6 additions & 2 deletions packages/utils/src/instrument/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ export function resetInstrumentationHandlers(): void {
/** Maybe run an instrumentation function, unless it was already called. */
export function maybeInstrument(type: InstrumentHandlerType, instrumentFn: () => void): void {
if (!instrumented[type]) {
instrumentFn();
instrumented[type] = true;
try {
instrumentFn();
instrumented[type] = true;
} catch (e) {
DEBUG_BUILD && logger.error('Error while instrumenting', e);
}
}
}

Expand Down
13 changes: 13 additions & 0 deletions packages/utils/test/instrument.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { maybeInstrument } from '../src';

describe('maybeInstrument', () => {
test('does not throw when instrumenting fails', () => {
maybeInstrument('xhr', () => {
throw new Error('test');
});
});

test('does not throw when instrumenting fn is not a function', () => {
maybeInstrument('xhr', undefined as any);
});
});
Loading