Skip to content

Commit 6729214

Browse files
chargomemydea
andauthored
fix(core): Silently fail maybeInstrument (#14140)
Co-authored-by: Francesco Novy <[email protected]>
1 parent 738870d commit 6729214

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

.size-limit.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ module.exports = [
224224
import: createImport('init'),
225225
ignore: ['next/router', 'next/constants'],
226226
gzip: true,
227-
limit: '39.1 KB',
227+
limit: '40 KB',
228228
},
229229
// SvelteKit SDK (ESM)
230230
{

packages/utils/src/instrument/handlers.ts

+5-1
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();
4140
instrumented[type] = true;
41+
try {
42+
instrumentFn();
43+
} catch (e) {
44+
DEBUG_BUILD && logger.error(`Error while instrumenting ${type}`, e);
45+
}
4246
}
4347
}
4448

+13
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)