Skip to content

Commit

Permalink
fix(core): Skip empty integrations (#7204)
Browse files Browse the repository at this point in the history
In the case when a user adds an empty integration, we want to handle this more gracefully instead of erroring out.
  • Loading branch information
mydea committed Feb 16, 2023
1 parent a8449de commit 5c4af0c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/core/src/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ export function setupIntegrations(integrations: Integration[]): IntegrationIndex
const integrationIndex: IntegrationIndex = {};

integrations.forEach(integration => {
setupIntegration(integration, integrationIndex);
// guard against empty provided integrations
if (integration) {
setupIntegration(integration, integrationIndex);
}
});

return integrationIndex;
Expand Down
16 changes: 16 additions & 0 deletions packages/core/test/lib/base.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,22 @@ describe('BaseClient', () => {
);
});

test('skips empty integrations', () => {
const options = getDefaultTestClientOptions({
dsn: PUBLIC_DSN,
// @ts-ignore we want to force invalid integrations here
integrations: [new TestIntegration(), null, undefined],
});
const client = new TestClient(options);
client.setupIntegrations();

client.captureEvent({ message: 'message' });

expect(TestClient.instance!.event!.sdk).toEqual({
integrations: ['TestIntegration'],
});
});

test('normalizes event with default depth of 3', () => {
expect.assertions(1);

Expand Down

0 comments on commit 5c4af0c

Please sign in to comment.