I want to return a non-zero exit code when my policy fails so that my CI/CD buildspec stops building. I also want to return a string error message from my rule(s).
I noticed the --fail and --fail-defined options for opa eval command. These options seem perfect. However, returning a string technically isn't 'failing' or returning 'undefined'. So, it seems to me impossible to return a string error message as well as a non-zero exit code without also sabotaging a good output string and test case.
Am I correct here? Is there any way to get the best of both worlds? I'm still new to Rego
Ex rego file:
package play
default hello := "hello failed"
hello := "hello passed" {
input.message == "world"
}
input:
{"message": "world"}
Running the following command will return a non-zero exit code no matter what
opa eval -i .\input.json -d .\test_rego.rego 'data.play.hello' --fail-defined -f raw
Similarly, the command below won't help because in this case the result is always defined
opa eval -i .\input.json -d .\test_rego.rego 'data.play.hello' --fail -f raw
Any help is appreciated