File tree Expand file tree Collapse file tree 2 files changed +26
-4
lines changed
packages/firestore/src/platform/browser Expand file tree Collapse file tree 2 files changed +26
-4
lines changed Original file line number Diff line number Diff line change 17
17
18
18
/** Formats an object as a JSON string, suitable for logging. */
19
19
export function formatJSON ( value : unknown ) : string {
20
- return JSON . stringify ( value ) ;
20
+ try {
21
+ return JSON . stringify ( value ) ;
22
+ } catch ( e : unknown ) {
23
+ return safeStringify ( value ) ;
24
+ }
25
+ }
26
+
27
+ /**
28
+ * Custom JSON stringification utilizing a replacer to work around common
29
+ * JSON.stringify(...) error cases: circular reference or bigint.
30
+ * @param value - object to stringify
31
+ */
32
+ function safeStringify ( value : unknown ) : string {
33
+ const cache = new Set ( ) ;
34
+ return JSON . stringify ( value , ( key , value ) => {
35
+ if ( typeof value === 'object' && value !== null ) {
36
+ if ( cache . has ( value ) ) {
37
+ return '[Circular]' ;
38
+ }
39
+ cache . add ( value ) ;
40
+ } else if ( typeof value === 'bigint' ) {
41
+ return value . toString ( ) ;
42
+ }
43
+ return value ;
44
+ } ) ;
21
45
}
Original file line number Diff line number Diff line change @@ -335,9 +335,7 @@ export class WebChannelConnection extends RestConnection {
335
335
logWarn (
336
336
LOG_TAG ,
337
337
`RPC '${ rpcName } ' stream ${ streamId } transport errored. Name:` ,
338
- err . name ,
339
- 'Message:' ,
340
- err . message
338
+ err
341
339
) ;
342
340
streamBridge . callOnClose (
343
341
new FirestoreError (
You can’t perform that action at this time.
0 commit comments