You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Exporting logs is currently failing with this error message:
```
Uncaught TypeError TypeError: Converting circular structure to JSON
--> starting at object with constructor 'LinkedHashMap'
| property 'hashCodeMap' -> object with constructor 'InternalHashCodeMap'
--- property 'host_0' closes the circle
at getReduxDataString (/Users/ericlin/dev/web-client-ui/packages/log/src/LogExport.ts:125:15)
```
We are handling circular references in `makeSafeToStringify()` before
calling `JSON.stringify()`, but it seems that some of them are not being
handled properly. This was tricky to debug since it was unclear to me
where/how exactly it was failing. I spent some time trying to fix our
custom implementation before settling with a library,
[safe-stable-stringify](https://www.npmjs.com/package/safe-stable-stringify)
(MIT license), that would handle circular structures and BigInt in a
[performant](https://github.com/BridgeAR/safe-stable-stringify?tab=readme-ov-file#performance--benchmarks)
way.
There are a few differences between our previous custom implementation
vs `safe-stable-stringify`:
- Circular references are replaced with “[Circular]”, whereas before we
also showed the path that the reference points to. This is a requested
feature that doesn't seem will be worked on
BridgeAR/safe-stable-stringify#43
- The order of keys are different when compared to previous logs. By
default the library guarantees a deterministic key order instead of
relying on insertion order, but this can be disabled to match the former
behaviour if desired.
- BigInts are converted to a number instead of a string in this library
The blacklist was updated with new entries to reduce the log size and
prevent length errors when exporting:
- For instance, the `client` object, which was already blacklisted, was
also found in a few other paths, which have now been blacklisted as
well.
Tested by:
- Exporting logs on an account with many queries successfully with a
reasonable size (62kb)
- Comparing the result to logs from before this issue and verified that
useful data has not been omitted.
Note:
After more testing, I tried using the new blacklist with our original
custom implementation, and it appears to also work. I narrowed it down
to `draftManager/draftStorage`, which seemed to be causing the circular
structure error.
However, when using the library, there is no error when serializing this
key, albeit producing a 31mb log file, indicating that there is still
something wrong with our implementation. We could solve this specific
issue by blacklisting this key, but switching to a library might be a
better idea to prevent such cases in the future.
* This tries to stringify each key of the object as an easy way to determine if it is safe
66
-
* If it fails to stringify, then the values that failed repeat the same steps recursively
67
-
* The unsafe objects are kept in a map with their path (e.g. root.someKey.someOtherKey)
68
-
* Then if the object is seen again, it must be a circular ref since that object could not be stringified safely
69
-
*
70
-
* @param obj Object to make safe to stringify
71
-
* @param blacklist List of JSON paths to blacklist. A JSON path is a list representing the path to that value (e.g. client.data would be `['client', 'data']`)
0 commit comments