Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v2.0.0-x] Error: Failed to resolve repeated object (this should not happen) #287

Closed
MikeRalphson opened this issue Jun 17, 2021 · 1 comment
Labels
bug Something isn't working

Comments

@MikeRalphson
Copy link
Contributor

Describe the bug

When stringifying an object containing multiple references to the same object which have been serialised as strings, the anchor mechanism seems to get confused.

To Reproduce

const yaml = require('yaml');

const o = {};

const d = new Date();

o.d1 = d;
o.d2 = d;

console.log(yaml.stringify(o));
/Users/mikeralphson/node/oad/node_modules/yaml/dist/doc/anchors.js:67
                    throw error;
                    ^

Error: Failed to resolve repeated object (this should not happen)
    at setAnchors (/Users/mikeralphson/node/oad/node_modules/yaml/dist/doc/anchors.js:64:35)
    at Document.createNode (/Users/mikeralphson/node/oad/node_modules/yaml/dist/doc/Document.js:110:9)
    at new Document (/Users/mikeralphson/node/oad/node_modules/yaml/dist/doc/Document.js:50:34)
    at Object.stringify (/Users/mikeralphson/node/oad/node_modules/yaml/dist/public-api.js:100:12)
    at Object.<anonymous> (/Users/mikeralphson/node/oad/bin/testyd.js:10:18)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12) {
  source: 2021-06-17T10:49:08.525Z,
  ref: { anchor: 'a1', node: null }
}

Expected behaviour

yaml.stringify should not throw an Error.

Versions (please complete the following information):

  • Environment: Node.js 14.16.0
  • yaml: 2.0.0-6

Additional context

yaml 1.x stringifies this as two strings without an anchor.

@MikeRalphson MikeRalphson added the bug Something isn't working label Jun 17, 2021
@eemeli
Copy link
Owner

eemeli commented Jun 18, 2021

Good catch! There was an early return when creating scalars that didn't take this into account. Should be fixed now.

@eemeli eemeli closed this as completed in d1faa5a Jun 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants