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

Missing error on parsed document for unresolved alias #497

Open
stefreak opened this issue Oct 9, 2023 · 1 comment
Open

Missing error on parsed document for unresolved alias #497

stefreak opened this issue Oct 9, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@stefreak
Copy link

stefreak commented Oct 9, 2023

Describe the bug
When parsing a document like this:

foo: *bar

The errors array on the parsed document is empty, and toJS will throw ReferenceError: Unresolved alias

To Reproduce

> const yaml = await import("yaml")
undefined
> const docs = yaml.parseAllDocuments("foo: *bar")
undefined
> docs.length
1
> docs[0].errors
[]
> docs[0].toJS()
Uncaught ReferenceError: Unresolved alias (the anchor must be set before the alias): bar
    at Alias.toJSON (/Users/steffen/work/github/garden/core/node_modules/yaml/dist/nodes/Alias.js:42:19)
    at Object.toJS (/Users/steffen/work/github/garden/core/node_modules/yaml/dist/nodes/toJS.js:22:26)
    at Object.addPairToJSMap (/Users/steffen/work/github/garden/core/node_modules/yaml/dist/nodes/addPairToJSMap.js:32:34)
    at YAMLMap.toJSON (/Users/steffen/work/github/garden/core/node_modules/yaml/dist/nodes/YAMLMap.js:124:28)
    at Object.toJS (/Users/steffen/work/github/garden/core/node_modules/yaml/dist/nodes/toJS.js:22:26)
    at Document.toJS (/Users/steffen/work/github/garden/core/node_modules/yaml/dist/doc/Document.js:301:26)
>

Expected behaviour
I expect an error on the document after calling yaml.parseAllDocuments.

> docs[0].errors.length
1

Versions (please complete the following information):

  • Environment: Node.js v18.15.0
  • yaml: 2.3.2
@stefreak stefreak added the bug Something isn't working label Oct 9, 2023
@stefreak stefreak changed the title No error on parsed document for unresolved alias Missing error on parsed document for unresolved alias Oct 9, 2023
@eemeli
Copy link
Owner

eemeli commented Oct 11, 2023

That's a fair concern. A method for discovering unresolved aliases should be provided, and a parsing option to include errors for them.

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