Skip to content

Commit 0e6cf14

Browse files
committed
feat: Better event name handling for non-Error objects
1 parent da2487e commit 0e6cf14

File tree

22 files changed

+186
-12
lines changed

22 files changed

+186
-12
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class MyTestClass {
2+
prop1 = 'value1';
3+
prop2 = 2;
4+
}
5+
6+
Sentry.captureException(new MyTestClass());
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { expect } from '@playwright/test';
2+
import type { Event } from '@sentry/types';
3+
4+
import { sentryTest } from '../../../../utils/fixtures';
5+
import { getFirstSentryEnvelopeRequest } from '../../../../utils/helpers';
6+
7+
sentryTest('should capture an POJO', async ({ getLocalTestPath, page }) => {
8+
const url = await getLocalTestPath({ testDir: __dirname });
9+
10+
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
11+
12+
expect(eventData.exception?.values).toHaveLength(1);
13+
expect(eventData.exception?.values?.[0]).toMatchObject({
14+
type: 'Error',
15+
value: '`MyTestClass` captured as exception with keys: prop1, prop2',
16+
mechanism: {
17+
type: 'generic',
18+
handled: true,
19+
},
20+
});
21+
});

packages/browser-integration-tests/suites/public-api/captureException/empty_obj/test.ts renamed to packages/browser-integration-tests/suites/public-api/captureException/emptyObj/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ sentryTest('should capture an empty object', async ({ getLocalTestPath, page })
1212
expect(eventData.exception?.values).toHaveLength(1);
1313
expect(eventData.exception?.values?.[0]).toMatchObject({
1414
type: 'Error',
15-
value: 'Non-Error exception captured with keys: [object has no keys]',
15+
value: 'Object captured as exception with keys: [object has no keys]',
1616
mechanism: {
1717
type: 'generic',
1818
handled: true,
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import * as Sentry from '@sentry/browser';
2+
3+
window.Sentry = Sentry;
4+
5+
Sentry.init({
6+
dsn: 'https://[email protected]/1337',
7+
defaultIntegrations: false,
8+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
window.addEventListener('error', function (event) {
2+
Sentry.captureException(event);
3+
});
4+
5+
window.thisDoesNotExist();
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { expect } from '@playwright/test';
2+
import type { Event } from '@sentry/types';
3+
4+
import { sentryTest } from '../../../../utils/fixtures';
5+
import { getFirstSentryEnvelopeRequest } from '../../../../utils/helpers';
6+
7+
sentryTest('should capture an ErrorEvent', async ({ getLocalTestPath, page }) => {
8+
const url = await getLocalTestPath({ testDir: __dirname });
9+
10+
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
11+
12+
expect(eventData.exception?.values).toHaveLength(1);
13+
expect(eventData.exception?.values?.[0]).toMatchObject({
14+
type: 'ErrorEvent',
15+
value: 'Event `ErrorEvent` captured as exception with message `Script error.`',
16+
mechanism: {
17+
type: 'generic',
18+
handled: true,
19+
},
20+
});
21+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Sentry.captureException(new Event('custom'));
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { expect } from '@playwright/test';
2+
import type { Event } from '@sentry/types';
3+
4+
import { sentryTest } from '../../../../utils/fixtures';
5+
import { getFirstSentryEnvelopeRequest } from '../../../../utils/helpers';
6+
7+
sentryTest('should capture an Event', async ({ getLocalTestPath, page }) => {
8+
const url = await getLocalTestPath({ testDir: __dirname });
9+
10+
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
11+
12+
expect(eventData.exception?.values).toHaveLength(1);
13+
expect(eventData.exception?.values?.[0]).toMatchObject({
14+
type: 'Event',
15+
value: 'Event `Event` (custom) captured as exception with keys: currentTarget, isTrusted, target, type',
16+
mechanism: {
17+
type: 'generic',
18+
handled: true,
19+
},
20+
});
21+
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Sentry.captureException({
2+
prop1: 'value1',
3+
prop2: 2,
4+
});

0 commit comments

Comments
 (0)