Skip to content

fix(utils): Make new non-enumerable properties mutable #4528

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
Feb 10, 2022
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: 1 addition & 1 deletion packages/utils/src/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ export function checkOrSetAlreadyCaught(exception: unknown): boolean {
try {
// set it this way rather than by assignment so that it's not ennumerable and therefore isn't recorded by the
// `ExtraErrorData` integration
addNonEnumerableProperty(exception, '__sentry_captured__', true);
addNonEnumerableProperty(exception as { [key: string]: unknown }, '__sentry_captured__', true);
} catch (err) {
// `exception` is a primitive, so we can't mark it seen
}
Expand Down
16 changes: 9 additions & 7 deletions packages/utils/src/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,18 @@ export function fill(source: { [key: string]: any }, name: string, replacementFa
}

/**
* Defines a non enumerable property. This creates a non enumerable property on an object.
* Defines a non-enumerable property on the given object.
*
* @param func The function to set a property to
* @param name the name of the special sentry property
* @param value the property to define
* @param obj The object on which to set the property
* @param name The name of the property to be set
* @param value The value to which to set the property
*/
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export function addNonEnumerableProperty(func: any, name: string, value: any): void {
Object.defineProperty(func, name, {
export function addNonEnumerableProperty(obj: { [key: string]: unknown }, name: string, value: unknown): void {
Object.defineProperty(obj, name, {
// enumerable: false, // the default, so we can save on bundle size by not explicitly setting it
value: value,
writable: true,
configurable: true,
});
}

Expand Down