0k / shyaml

YAML for command line
BSD 2-Clause "Simplified" License
767 stars 57 forks source link

If no key exists in the file, get-value gives huge stack trace #34

Closed kirhgoff closed 6 years ago

kirhgoff commented 7 years ago

To use with big amounts of files I expect shyaml to report empty value for any key, but instead I am getting that:

cat somefile.yml | shyaml get-value abrakadabra Traceback (most recent call last): File "/Users/klastovirya/.pyenv/versions/3.3.6/bin/shyaml", line 308, in aget value = dct[head] KeyError: 'dsfdgfdfgf'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/Users/klastovirya/.pyenv/versions/3.3.6/bin/shyaml", line 378, in main value = mget(contents, key_value) File "/Users/klastovirya/.pyenv/versions/3.3.6/bin/shyaml", line 248, in mget return aget(dct, tokenize(key)) File "/Users/klastovirya/.pyenv/versions/3.3.6/bin/shyaml", line 313, in aget % (head, )) main.MissingKeyError During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/Users/klastovirya/.pyenv/versions/3.3.6/bin/shyaml", line 429, in sys.exit(main(sys.argv[1:])) File "/Users/klastovirya/.pyenv/versions/3.3.6/bin/shyaml", line 385, in main msg = str(exc.message) AttributeError: 'MissingKeyError' object has no attribute 'message'

vaab commented 7 years ago

Thanks for the report. I'll probably implement something in this taste:

vaab commented 7 years ago

Of course, while waiting for that, you can use:

cat somefile.yml | shyaml get-value abrakadabra 2>/dev/null

To get exactly what you wanted. Just in case you didn't know.

kirhgoff commented 7 years ago

I wrote my own gem for my task, just wanted to let you know there is a problem

vaab commented 6 years ago

I just removed the exception that was basically occurring because of a python3 incompatibility. Thanks for your reports, and sorry for the long delay.