Skip to content

Commit 5be6891

Browse files
authored
fix: TypeError read-only property (#1842)
* fix: typeerror read-only property * fix: Tests
1 parent 30909d5 commit 5be6891

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
- [core]: fix: Error in extraErrorData integration where event would not be send in case of non assignable object property.
6+
57
## 4.5.2
68

79
- [utils] fix: Decycling for objects to no produce an endless loop

packages/core/src/integrations/extraerrordata.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { addGlobalEventProcessor, getCurrentHub } from '@sentry/hub';
22
import { Integration, SentryEvent, SentryEventHint } from '@sentry/types';
3-
import { isError } from '@sentry/utils/is';
4-
import { logger } from '../../../utils/logger';
3+
import { isError, isString } from '@sentry/utils/is';
4+
import { logger } from '@sentry/utils/logger';
5+
import { safeNormalize } from '@sentry/utils/object';
56

67
/**
78
* Just an Error object with arbitrary attributes attached to it.
@@ -46,12 +47,19 @@ export class ExtraErrorData implements Integration {
4647
const errorData = this.extractErrorData(hint.originalException);
4748

4849
if (errorData) {
50+
let extra = {
51+
...event.extra,
52+
};
53+
const normalizedErrorData = safeNormalize(errorData);
54+
if (!isString(normalizedErrorData)) {
55+
extra = {
56+
...event.extra,
57+
...normalizedErrorData,
58+
};
59+
}
4960
return {
5061
...event,
51-
extra: {
52-
...event.extra,
53-
...errorData,
54-
},
62+
extra,
5563
};
5664
}
5765

@@ -62,6 +70,7 @@ export class ExtraErrorData implements Integration {
6270
* Extract extra information from the Error object
6371
*/
6472
private extractErrorData(error: ExtendedError): { [key: string]: unknown } | null {
73+
let result = null;
6574
// We are trying to enhance already existing event, so no harm done if it won't succeed
6675
try {
6776
const nativeKeys = ['name', 'message', 'stack', 'line', 'column', 'fileName', 'lineNumber', 'columnNumber'];
@@ -77,15 +86,14 @@ export class ExtraErrorData implements Integration {
7786
}
7887
extraErrorInfo[key] = value;
7988
}
80-
return {
89+
result = {
8190
[name]: extraErrorInfo,
8291
};
8392
}
84-
85-
return null;
8693
} catch (oO) {
8794
logger.error('Unable to extract extra data from the Error object:', oO);
88-
return null;
8995
}
96+
97+
return result;
9098
}
9199
}

0 commit comments

Comments
 (0)