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

YQ gives invalid/useless error description while processing an invalid yaml document #561

Open
sk4zuzu opened this issue Oct 9, 2020 · 1 comment
Labels

Comments

@sk4zuzu
Copy link

sk4zuzu commented Oct 9, 2020

Describe the bug

YQ gives invalid/useless error description while processing an invalid yaml document.

version of yq:

$ yq -V
yq version 3.4.0

operating system: linux amd64, the yq binary was installed from github releases manually

Input Yaml

An invalid document:

aaa:
  bbb: x
  ccc: "["y":1]"

Command

So far we tried:

$ yq r test.yml aaa.bbb

and

$ yq w test.yml aaa.bbb test

Actual behavior

$ yq r test.yml aaa.bbb
Error: yaml: line 1: did not find expected key
$ yq w test.yml aaa.bbb test
Error: Error reading document at index 0, yaml: line 1: did not find expected key: yaml: line 1: did not find expected key
Usage:
  yq write [yaml_file] [path_expression] [value] [flags]

Aliases:
  write, w

Examples:

yq write things.yaml 'a.b.c' true
yq write things.yaml 'a.*.c' true
yq write things.yaml 'a.**' true
yq write things.yaml 'a.(child.subchild==co*).c' true
yq write things.yaml 'a.b.c' --tag '!!str' true # force 'true' to be interpreted as a string instead of bool
yq write things.yaml 'a.b.c' --tag '!!float' 3
yq write --inplace -- things.yaml 'a.b.c' '--cat' # need to use '--' to stop processing arguments as flags
yq w -i things.yaml 'a.b.c' cat
yq w -i -s update_script.yaml things.yaml
yq w things.yaml 'a.b.d[+]' foo # appends a new node to the 'd' array
yq w --doc 2 things.yaml 'a.b.d[+]' foo # updates the 3rd document of the yaml file


Flags:
      --anchorName string   anchor name
  -d, --doc string          process document index number (0 based, * for all documents) (default "0")
  -f, --from string         yaml file for updating yaml (as-is)
  -h, --help                help for write
  -i, --inplace             update the yaml file inplace
      --makeAlias           create an alias using the value as the anchor name
  -s, --script string       yaml script for updating yaml
      --style string        formatting style of the value: single, double, folded, flow, literal, tagged
  -t, --tag string          set yaml tag (e.g. !!int)

Global Flags:
  -C, --colors        print with colors
  -I, --indent int    sets indent level for output (default 2)
  -P, --prettyPrint   pretty print
  -j, --tojson        output as json. By default it prints a json document in one line, use the prettyPrint flag to print a formatted doc.
  -v, --verbose       verbose mode

Expected behavior

Possibly an error message with some line number indicating where the syntax error is? 🤔

Additional context

This has some nice potential for wasting unaware user's time 👍😇. This happened to my colleague. We get it that the document was incorrect, but yq didn't help us... 😭

Thanks for the great tool! 😍

@sk4zuzu sk4zuzu added the bug label Oct 9, 2020
@j-zimnowoda
Copy link

Yes, and please do not print the Usage sting if provided file has invalid content.
The Usage string should be only printed if a command arguments are invalid or missing.

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