question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cleaner command line error output

See original GitHub issue

Currently, when yamale is used from the command line and an error is found the output is difficult to parse since schema.validate() will raise and then command_line.main() will also raise. The raise() from command_line.main() doesn’t actually add anything new and the raise() from validate() includes the python stack it makes it hard to find the actual problem - I’m only really interested in what yamale found, not the methods it called to find them.

To deal with this locally, I made some very simple changes that I’d be happy to contribute back if you’re interested. In command_line.main(), I simply wrapped the call to _router():

try:
    _router(args.path, args.schema, args.cpu_num, args.parser, args.strict)
except ValueError:
    # Already processed
    pass
else:
    print('Validation success! 👍')

To get rid of the python stack from the output, I changed one line in command_line._validate() from error += traceback.format_exc() to error += str(e).

With those changes, I was able to change this output

Validating /Users/televi/foo.yaml...

Error!
Schema: bar.yaml
Data file: /Users/televi/foo.yaml
Traceback (most recent call last):
  File "/Users/televi/.venv/lib/python3.6/site-packages/yamale/command_line.py", line 29, in _validate
    yamale.validate(schema, data, strict)
  File "/Users/televi/.venv/lib/python3.6/site-packages/yamale/yamale.py", line 38, in validate
    schema.validate(d, path, strict)
  File "/Users/televi/.venv/lib/python3.6/site-packages/yamale/schema/schema.py", line 65, in validate
    raise ValueError(error_str)
ValueError:
Error validating data /Users/televi/foo.yaml with schema bar.yaml
	borg: 'None' is not a str.

Traceback (most recent call last):
  File "/Users/televi/.venv/lib/python3.6/site-packages/yamale/command_line.py", line 29, in _validate
    yamale.validate(schema, data, strict)
  File "/Users/televi/.venv/lib/python3.6/site-packages/yamale/yamale.py", line 38, in validate
    schema.validate(d, path, strict)
  File "/Users/televi/.venv/lib/python3.6/site-packages/yamale/schema/schema.py", line 65, in validate
    raise ValueError(error_str)
ValueError:
Error validating data /Users/televi/foo.yaml with schema bar.yaml
	borg: 'None' is not a str.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/televi/.venv/bin/yamale", line 11, in <module>
    load_entry_point('yamale==2.0', 'console_scripts', 'yamale')()
  File "/Users/televi/.venv/lib/python3.6/site-packages/yamale/command_line.py", line 115, in main
    _router(args.path, args.schema, args.cpu_num, args.parser, args.strict)
  File "/Users/televi/.venv/lib/python3.6/site-packages/yamale/command_line.py", line 97, in _router
    _validate_single(root, schema_name, parser, strict)
  File "/Users/televi/.venv/lib/python3.6/site-packages/yamale/command_line.py", line 68, in _validate_single
    _validate(s, yaml_path, parser, strict)
  File "/Users/televi/.venv/lib/python3.6/site-packages/yamale/command_line.py", line 36, in _validate
    raise ValueError('Validation failed!')
ValueError: Validation failed!

to this output

Validating /Users/televi/foo.yaml...

Error!
Schema: bar.yaml
Data file: /Users/televi/foo.yaml

Error validating data /Users/televi/foo.yaml with schema bar.yaml
	borg: 'None' is not a str.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
televicommented, Nov 7, 2019

In looking a bit more it may be useful to print an error in _validate_singleton() when the file isn’t found - else we may bury that error by mistake.

We could also simply print Validation failed! to provide a grepable string instead of passing or better yet exit with a non-zero code or both.

0reactions
mildebrandtcommented, Jan 13, 2020

I agree, thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Suppress command line output - batch file - Stack Overflow
If "test.exe" is not running, I get this message: ERROR: The process "test.exe" not found. Why does this error message get displayed, even ......
Read more >
Cleanup redirected output file from failed command
It would redirect STDOUT output to a file; If the command fails it would remove output file; In all case it would return...
Read more >
Modify 2>&1 so that output goes to a specific file and any ...
Yes, this is possible. The 2>&1 means the following: 2 : stderr > : output redirect & : copy file descriptor 1 :...
Read more >
Windows Batch File Tips and Tricks - PushMon
Basic tips and tricks in writing windows batch files.
Read more >
Linux Redirect Error Output To File - nixCraft
Linux Redirect Error Output To File ; Syntax To redirect all output to file. The syntax is as follows to redirect output (stdout)...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found