github.com/argoproj/argo-cd/v2@v2.10.9/test/e2e/fixture/applicationsets/utils/errrors.go (about) 1 package utils 2 3 import ( 4 "os" 5 "runtime/debug" 6 7 log "github.com/sirupsen/logrus" 8 ) 9 10 const ( 11 // ErrorCommandSpecific is reserved for command specific indications 12 ErrorCommandSpecific = 1 13 // ErrorConnectionFailure is returned on connection failure to API endpoint 14 ErrorConnectionFailure = 11 15 // ErrorAPIResponse is returned on unexpected API response, i.e. authorization failure 16 ErrorAPIResponse = 12 17 // ErrorResourceDoesNotExist is returned when the requested resource does not exist 18 ErrorResourceDoesNotExist = 13 19 // ErrorGeneric is returned for generic error 20 ErrorGeneric = 20 21 ) 22 23 // CheckError logs a fatal message and exits with ErrorGeneric if err is not nil 24 func CheckError(err error) { 25 if err != nil { 26 debug.PrintStack() 27 Fatal(ErrorGeneric, err) 28 } 29 } 30 31 // CheckErrorWithCode is a convenience function to exit if an error is non-nil and exit if it was 32 func CheckErrorWithCode(err error, exitcode int) { 33 if err != nil { 34 Fatal(exitcode, err) 35 } 36 } 37 38 // FailOnErr panics if there is an error. It returns the first value so you can use it if you cast it: 39 // text := FailOrErr(Foo)).(string) 40 func FailOnErr(v interface{}, err error) interface{} { 41 CheckError(err) 42 return v 43 } 44 45 // Fatal is a wrapper for logrus.Fatal() to exit with custom code 46 func Fatal(exitcode int, args ...interface{}) { 47 exitfunc := func() { 48 os.Exit(exitcode) 49 } 50 log.RegisterExitHandler(exitfunc) 51 log.Fatal(args...) 52 } 53 54 // Fatalf is a wrapper for logrus.Fatalf() to exit with custom code 55 func Fatalf(exitcode int, format string, args ...interface{}) { 56 exitfunc := func() { 57 os.Exit(exitcode) 58 } 59 log.RegisterExitHandler(exitfunc) 60 log.Fatalf(format, args...) 61 }