Skip to content

Commit a80672f

Browse files
committed
Use contexts to handle extra error data
1 parent 01bab2d commit a80672f

File tree

2 files changed

+12
-34
lines changed

2 files changed

+12
-34
lines changed

packages/integrations/src/extraerrordata.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,21 @@ export class ExtraErrorData implements Integration {
4747
const errorData = this._extractErrorData(hint.originalException as ExtendedError);
4848

4949
if (errorData) {
50-
let extra = {
51-
...event.extra,
50+
let contexts = {
51+
...event.contexts,
5252
};
5353

5454
const normalizedErrorData = normalize(errorData, this._options.depth);
5555
if (isPlainObject(normalizedErrorData)) {
56-
extra = {
57-
...event.extra,
56+
contexts = {
57+
...event.contexts,
5858
...normalizedErrorData,
5959
};
6060
}
6161

6262
return {
6363
...event,
64-
extra,
64+
contexts,
6565
};
6666
}
6767

@@ -76,7 +76,6 @@ export class ExtraErrorData implements Integration {
7676
// We are trying to enhance already existing event, so no harm done if it won't succeed
7777
try {
7878
const nativeKeys = ['name', 'message', 'stack', 'line', 'column', 'fileName', 'lineNumber', 'columnNumber'];
79-
const name = error.name || error.constructor.name;
8079
const errorKeys = Object.getOwnPropertyNames(error).filter(key => nativeKeys.indexOf(key) === -1);
8180

8281
if (errorKeys.length) {
@@ -89,9 +88,7 @@ export class ExtraErrorData implements Integration {
8988
// tslint:disable:no-unsafe-any
9089
extraErrorInfo[key] = value;
9190
}
92-
result = {
93-
[name]: extraErrorInfo,
94-
};
91+
result = extraErrorInfo;
9592
}
9693
} catch (oO) {
9794
logger.error('Unable to extract extra data from the Error object:', oO);

packages/integrations/test/extraerrordata.test.ts

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,15 @@ describe('ExtraErrorData()', () => {
1919
originalException: error,
2020
});
2121

22-
expect(enhancedEvent.extra).toEqual({
23-
TypeError: {
24-
baz: 42,
25-
foo: 'bar',
26-
},
27-
});
28-
});
29-
30-
it('doesnt choke on linked errors and stringify names instead', () => {
31-
const error = new TypeError('foo') as ExtendedError;
32-
error.cause = new SyntaxError('bar');
33-
34-
const enhancedEvent = extraErrorData.enhanceEventWithErrorData(event, {
35-
originalException: error,
36-
});
37-
38-
expect(enhancedEvent.extra).toEqual({
39-
TypeError: {
40-
cause: 'SyntaxError: bar',
41-
},
22+
expect(enhancedEvent.contexts).toEqual({
23+
baz: 42,
24+
foo: 'bar',
4225
});
4326
});
4427

4528
it('should not remove previous data existing in extra field', () => {
4629
event = {
47-
extra: {
30+
contexts: {
4831
foo: 42,
4932
},
5033
};
@@ -55,10 +38,8 @@ describe('ExtraErrorData()', () => {
5538
originalException: error,
5639
});
5740

58-
expect(enhancedEvent.extra).toEqual({
59-
TypeError: {
60-
baz: 42,
61-
},
41+
expect(enhancedEvent.contexts).toEqual({
42+
baz: 42,
6243
foo: 42,
6344
});
6445
});

0 commit comments

Comments
 (0)