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

Traceback on yaml anchor #5

Open
MatthewScholefield opened this issue Nov 15, 2021 · 1 comment
Open

Traceback on yaml anchor #5

MatthewScholefield opened this issue Nov 15, 2021 · 1 comment

Comments

@MatthewScholefield
Copy link

When parsing a yaml file with an anchor, yaml2jsonnet generates a traceback:

$ cat anchor-example.yaml
foo: &foo-ref
  key-1: "val-1"
  key-2: "val-2"
var: *foo-ref
$ yaml2jsonnet anchor-example.yaml
Traceback (most recent call last):
  File "/home/user/.local/bin/yaml2jsonnet", line 8, in <module>
    sys.exit(main())
  File "/home/user/.local/lib/python3.9/site-packages/yaml2jsonnet/cli.py", line 58, in main
    run(args)
  File "/home/user/.local/lib/python3.9/site-packages/yaml2jsonnet/cli.py", line 47, in run
    convert_yaml(yaml_data, args.out, args.document_comments)
  File "/home/user/.local/lib/python3.9/site-packages/yaml2jsonnet/yaml2jsonnet.py", line 14, in convert_yaml
    JsonnetRenderer(events, output, array, inject_comments).render()
  File "/home/user/.local/lib/python3.9/site-packages/yaml2jsonnet/jsonnet_renderer.py", line 210, in render
    self.state.send(event)
  File "/home/user/.local/lib/python3.9/site-packages/yaml2jsonnet/jsonnet_renderer.py", line 383, in _mapping_value
    raise UnhandledEventError(self, event)
yaml2jsonnet.jsonnet_renderer.UnhandledEventError: Event was not handled by the current state: Last event was AliasEvent(anchor='foo-ref'), the state was _mapping_value, the queue was [(StreamStartEvent,_start), (DocumentStartEvent,_stream), (MappingStartEvent,_document)]

Instead it'd be nice to show an error like "Yaml anchors are not supported. Please remove them and try again."

@waisbrot
Copy link
Owner

The UnhandledEventError is for unknown unknowns, so to speak. I didn't remember that anchors were a thing and never tested them. If you've got an idea for how to handle generic errors in a friendlier way, though, I'm interested.

The YAML parsing library that I'm using seems to handle anchors (it's not giving an error, it's giving me an event that I'm not handling). Presumably, it'd be pretty easy to add anchors. If I get some time, I'll try adding it.

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

No branches or pull requests

2 participants