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

[misleading message] Error: yaml: line 3: did not find expected key #1030

Closed
ryenus opened this issue Dec 6, 2021 · 3 comments
Closed

[misleading message] Error: yaml: line 3: did not find expected key #1030

ryenus opened this issue Dec 6, 2021 · 3 comments
Labels

Comments

@ryenus
Copy link
Contributor

ryenus commented Dec 6, 2021

Describe the bug
When an item in an array is indented wrong, the error message reported is unclear, and it points to the wrong line.

Version of yq: 4.16.1
Operating system: mac
Installed via: homebrew

Input Yaml
Concise yaml document(s) (as simple as possible to show the bug, please keep it to 10 lines or less)
data1.yml:

- item: 1
  attr: 1
- item: 2
  attr: 2
- item: 3
  attr: 3
- item: 4
  attr: 4

data2.yml:

- item: 1
  attr: 1
- item: 2
  attr: 2
- item: 3
  attr: 3
  - item: 4
  attr: 4

Command
The command you ran:

yq -oj e . data1.yaml data2.yaml

Actual behavior

... // data1.yaml converted to json properly
Error: yaml: line 4: did not find expected key

Expected behavior

Error: data2.yaml: line 7: bad indentation

Additional context
Here the problem is the bad indentation on line 7 with the 4th item in the array, but the reported error is:

Error: yaml: line 4: did not find expected key

Where the item 2 with attr 2 looks just fine, it doesn't even point to item 3, which makes it confusing and not helpful with locating the actual problem.

And the difference between the actual line and the reported line could be quite large when item 3 takes many lines.

Also it should report the file name whenever available, this would be very helpful when processing multiple input files.

Nevertheless, thank you very much for making yq, it's very useful, especially in places where json is too strict and jq refuse to work, that's when yq would come and rescue :-)

@mikefarah
Copy link
Owner

I can't do much about the error message, as that comes from the underlying go-yaml parser. I can however report the filename - that makes a lot of sense too 👍🏼

@ryenus
Copy link
Contributor Author

ryenus commented Dec 6, 2021

@mikefarah possible to report it to upstream? appreciate if you can help with the context you know :-)

@mikefarah
Copy link
Owner

Closing as dupe of #561

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

No branches or pull requests

2 participants