Bash running cli command over and over when exit code is 1

40 views Asked by At

I am working on a pre-commit hook bash script that makes use of a cli tool (snyk). Here is an example:

#!/usr/bin/env bash
echo "running snyk code test"
snyk code test

If I invoke the above using "pre-commit run --all-files" the tool runs as expected however it runs multiple times.

When this occurs the exit code is 1

If I then modify the script to include a flag that I know will result in a pass

#!/usr/bin/env bash
echo "running snyk code test"
snyk code test --severity-threshold=high

The script will run once and results in an exit code of 0.

Is this behavior related to a lack of error handling in my script? If so could someone please show me how to catch the exception so the command runs once the script fails and returns an exit code of 1.

0

There are 0 answers