Skip to content

Commit 5c4af0c

Browse files
authored
fix(core): Skip empty integrations (#7204)
In the case when a user adds an empty integration, we want to handle this more gracefully instead of erroring out.
1 parent a8449de commit 5c4af0c

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

packages/core/src/integration.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,10 @@ export function setupIntegrations(integrations: Integration[]): IntegrationIndex
8888
const integrationIndex: IntegrationIndex = {};
8989

9090
integrations.forEach(integration => {
91-
setupIntegration(integration, integrationIndex);
91+
// guard against empty provided integrations
92+
if (integration) {
93+
setupIntegration(integration, integrationIndex);
94+
}
9295
});
9396

9497
return integrationIndex;

packages/core/test/lib/base.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,22 @@ describe('BaseClient', () => {
697697
);
698698
});
699699

700+
test('skips empty integrations', () => {
701+
const options = getDefaultTestClientOptions({
702+
dsn: PUBLIC_DSN,
703+
// @ts-ignore we want to force invalid integrations here
704+
integrations: [new TestIntegration(), null, undefined],
705+
});
706+
const client = new TestClient(options);
707+
client.setupIntegrations();
708+
709+
client.captureEvent({ message: 'message' });
710+
711+
expect(TestClient.instance!.event!.sdk).toEqual({
712+
integrations: ['TestIntegration'],
713+
});
714+
});
715+
700716
test('normalizes event with default depth of 3', () => {
701717
expect.assertions(1);
702718

0 commit comments

Comments
 (0)