Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

Using Flat module to flatten circular objects crashes stack #23

Closed
sgrasso opened this issue Feb 20, 2019 · 1 comment
Closed

Using Flat module to flatten circular objects crashes stack #23

sgrasso opened this issue Feb 20, 2019 · 1 comment

Comments

@sgrasso
Copy link

sgrasso commented Feb 20, 2019

Flat doesn't handle circular references in objects correctly. This creates node to blow up running out of heap memory when trying to log.

See Flat issue here.
hughsk/flat#24

Perhaps just using the fast-safe-stringify to do a replacer prior to passing it to Flat in the Flatten method.

From fast-safe-stringify's README...

const safeStringify = require('fast-safe-stringify')

function replacer(key, value) {
  console.log('Key:', JSON.stringify(key), 'Value:', JSON.stringify(value))
  // Remove the circular structure
  if (value === '[Circular]') {
    return
  }
  return value
}
const serialized = safeStringify(o, replacer, 2)
// Key: "" Value: {"a":1,"o":"[Circular]"}
// Key: "a" Value: 1
// Key: "o" Value: "[Circular]"
@jessie-codes
Copy link
Owner

Fixed in commit d7ffb3a

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants