Skip to content

Commit 3d4c98f

Browse files
committed
deal with difficult-to-seriallize primitives
1 parent ff69361 commit 3d4c98f

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

MIGRATION.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ We realized how annoying it is to set a whole object using `setExtra`, so there
9292
`Scope`.
9393

9494
```typescript
95-
setTags(tags: { [key: string]: string | number | boolean | bigint| symbol| null | undefined }): this;
95+
setTags(tags: { [key: string]: string | number | boolean | null | undefined }): this;
9696
setExtras(extras: { [key: string]: any }): this;
9797
clearBreadcrumbs(): this;
9898
```

packages/utils/src/object.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,13 @@ export function normalizeToSize<T>(
171171
}
172172

173173
/**
174-
* Transform any non-primitive or Symbol-type value into a string. Acts as a no-op on non-Symbol primitives.
174+
* Transform any non-primitive, BigInt, or Symbol-type value into a string. Acts as a no-op on strings, numbers,
175+
* booleans, null, and undefined.
175176
*
176177
* @param value The value to stringify
177-
* @returns For non-primitive and Symbol-type values, a string denoting the value's type, or in the case of a Symbol,
178-
* its type and description. For non-Symbol primitives, the original value, unchanged.
178+
* @returns For non-primitive, BigInt, and Symbol-type values, a string denoting the value's type, type and value, or
179+
* type and `description` property, respectively. For non-BigInt, non-Symbol primitives, returns the original value,
180+
* unchanged.
179181
*/
180182
function serializeValue(value: any): any {
181183
const type = Object.prototype.toString.call(value);
@@ -242,10 +244,16 @@ function normalizeValue<T>(value: T, key?: any): T | string {
242244
return `[Function: ${getFunctionName(value)}]`;
243245
}
244246

247+
// symbols and bigints are considered primitives by TS, but aren't natively JSON-serilaizable
248+
245249
if (typeof value === 'symbol') {
246250
return `[${String(value)}]`;
247251
}
248252

253+
if (typeof value === 'bigint') {
254+
return `[BigInt: ${String(value)}]`;
255+
}
256+
249257
return value;
250258
}
251259

0 commit comments

Comments
 (0)