Skip to content

Missing error on parsed document for unresolved alias #497

@stefreak

Description

@stefreak

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions