Skip to content

fix: TypeError read-only property #1842

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- [core]: fix: Error in extraErrorData integration where event would not be send in case of non assignable object property.

## 4.5.2

- [utils] fix: Decycling for objects to no produce an endless loop
Expand Down
28 changes: 18 additions & 10 deletions packages/core/src/integrations/extraerrordata.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { addGlobalEventProcessor, getCurrentHub } from '@sentry/hub';
import { Integration, SentryEvent, SentryEventHint } from '@sentry/types';
import { isError } from '@sentry/utils/is';
import { logger } from '../../../utils/logger';
import { isError, isString } from '@sentry/utils/is';
import { logger } from '@sentry/utils/logger';
import { safeNormalize } from '@sentry/utils/object';

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

if (errorData) {
let extra = {
...event.extra,
};
const normalizedErrorData = safeNormalize(errorData);
if (!isString(normalizedErrorData)) {
extra = {
...event.extra,
...normalizedErrorData,
};
}
return {
...event,
extra: {
...event.extra,
...errorData,
},
extra,
};
}

Expand All @@ -62,6 +70,7 @@ export class ExtraErrorData implements Integration {
* Extract extra information from the Error object
*/
private extractErrorData(error: ExtendedError): { [key: string]: unknown } | null {
let result = null;
// We are trying to enhance already existing event, so no harm done if it won't succeed
try {
const nativeKeys = ['name', 'message', 'stack', 'line', 'column', 'fileName', 'lineNumber', 'columnNumber'];
Expand All @@ -77,15 +86,14 @@ export class ExtraErrorData implements Integration {
}
extraErrorInfo[key] = value;
}
return {
result = {
[name]: extraErrorInfo,
};
}

return null;
} catch (oO) {
logger.error('Unable to extract extra data from the Error object:', oO);
return null;
}

return result;
}
}