safety icon indicating copy to clipboard operation
safety copied to clipboard

README Feature: Error codes for check

Open normoes opened this issue 6 years ago • 2 comments

I would love to see a short section about the error codes of check.

Black (under Command line options) does that and it helped me a lot:

--check                     Don't write the files back, just return the
                              status.  Return code 0 means nothing would
                              change.  Return code 1 means some files would be
                              reformatted.  Return code 123 means there was an
                              internal error.

I found this in safety/cli.py (line 90) to be very helpful:

sys.exit(-1 if vulns else 0)

normoes avatar Jan 11 '19 09:01 normoes

Actually it seems -1 is the only exit code ever returned (besides 0). It would be really useful for me to differentiate between a technical failure and "vulnerabilities being found".

I use safety check --bare in a cronjob and I want my cronjob to fail loudly if safety could not run, but just report the vulnerabilities if run successfully. A flag like --exit-0-even-if-vulnerabilities-found or something would also fit my needs.

wadevries avatar Jun 11 '19 08:06 wadevries

@wadevries Actually, you are right. It would further improve safety, especially when run in CI jobs. That's exactly my use case as well.

normoes avatar Jun 15 '19 19:06 normoes

Hi @normoes and @wadevries, the latest Safety version added support for standard error codes. You can find the code and its meaning in the README: https://github.com/pyupio/safety#using-safety-with-a-ci-service

yeisonvargasf avatar Oct 12 '22 18:10 yeisonvargasf