Skip to content

Commit

Permalink
Fixed circular reference json serialization error.
Browse files Browse the repository at this point in the history
  • Loading branch information
BogdanHabic committed Nov 13, 2019
1 parent 7bd5a5c commit 695188d
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion truffle/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,22 @@ func GetTruffleConfig(configName string, projectDir string) (*Config, error) {
data, err := exec.Command("node", "-e", fmt.Sprintf(`
var config = require("%s");
console.log("%s" + JSON.stringify(config) + "%s");
var cache = [];
var jsonConfig = JSON.stringify(config, (key, value) => {
if (typeof value === 'object' && value !== null) {
if (cache.indexOf(value) !== -1) {
// Circular reference found, discard key
return;
}
// Store value in our collection
cache.push(value);
}
return value;
}, '');
console.log("%s" + jsonConfig + "%s");
process.exit(0);
`, trufflePath, divider, divider)).CombinedOutput()
if err != nil {
return nil, fmt.Errorf("cannot evaluate %s, tried path: %s, error: %s, output: %s", configName, trufflePath, err, string(data))
Expand Down

0 comments on commit 695188d

Please sign in to comment.