Skip to content

Commit d64568a

Browse files
CPatchanekamilogorek
authored andcommitted
feat: Use contexts to handle ExtraErrorData (getsentry#2208)
* Use contexts to handle extra error data * Update travis ubuntu distro
1 parent c9339c1 commit d64568a

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ install: true
1212
sudo: required
1313

1414
language: node_js
15-
dist: trusty
15+
dist: bionic
1616

1717
cache:
1818
yarn: true

packages/integrations/src/extraerrordata.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -43,25 +43,28 @@ export class ExtraErrorData implements Integration {
4343
if (!hint || !hint.originalException || !isError(hint.originalException)) {
4444
return event;
4545
}
46+
const name = (hint.originalException as ExtendedError).name || hint.originalException.constructor.name;
4647

4748
const errorData = this._extractErrorData(hint.originalException as ExtendedError);
4849

4950
if (errorData) {
50-
let extra = {
51-
...event.extra,
51+
let contexts = {
52+
...event.contexts,
5253
};
5354

5455
const normalizedErrorData = normalize(errorData, this._options.depth);
5556
if (isPlainObject(normalizedErrorData)) {
56-
extra = {
57-
...event.extra,
58-
...normalizedErrorData,
57+
contexts = {
58+
...event.contexts,
59+
[name]: {
60+
...normalizedErrorData,
61+
},
5962
};
6063
}
6164

6265
return {
6366
...event,
64-
extra,
67+
contexts,
6568
};
6669
}
6770

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

8284
if (errorKeys.length) {
@@ -89,9 +91,7 @@ export class ExtraErrorData implements Integration {
8991
// tslint:disable:no-unsafe-any
9092
extraErrorInfo[key] = value;
9193
}
92-
result = {
93-
[name]: extraErrorInfo,
94-
};
94+
result = extraErrorInfo;
9595
}
9696
} catch (oO) {
9797
logger.error('Unable to extract extra data from the Error object:', oO);

packages/integrations/test/extraerrordata.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe('ExtraErrorData()', () => {
1919
originalException: error,
2020
});
2121

22-
expect(enhancedEvent.extra).toEqual({
22+
expect(enhancedEvent.contexts).toEqual({
2323
TypeError: {
2424
baz: 42,
2525
foo: 'bar',
@@ -35,7 +35,7 @@ describe('ExtraErrorData()', () => {
3535
originalException: error,
3636
});
3737

38-
expect(enhancedEvent.extra).toEqual({
38+
expect(enhancedEvent.contexts).toEqual({
3939
TypeError: {
4040
cause: 'SyntaxError: bar',
4141
},
@@ -44,7 +44,7 @@ describe('ExtraErrorData()', () => {
4444

4545
it('should not remove previous data existing in extra field', () => {
4646
event = {
47-
extra: {
47+
contexts: {
4848
foo: 42,
4949
},
5050
};
@@ -55,7 +55,7 @@ describe('ExtraErrorData()', () => {
5555
originalException: error,
5656
});
5757

58-
expect(enhancedEvent.extra).toEqual({
58+
expect(enhancedEvent.contexts).toEqual({
5959
TypeError: {
6060
baz: 42,
6161
},

0 commit comments

Comments
 (0)