The external provider needs a simple way to indicate certain types of errors. Duplicate error and not found error are such an example. Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
26 lines
540 B
Go
26 lines
540 B
Go
package execution
|
|
|
|
import (
|
|
"errors"
|
|
|
|
gErrors "github.com/cloudbase/garm/errors"
|
|
)
|
|
|
|
const (
|
|
// ExitCodeNotFound is an exit code that indicates a Not Found error
|
|
ExitCodeNotFound int = 30
|
|
// ExitCodeDuplicate is an exit code that indicates a duplicate error
|
|
ExitCodeDuplicate int = 31
|
|
)
|
|
|
|
func ResolveErrorToExitCode(err error) int {
|
|
if err != nil {
|
|
if errors.Is(err, gErrors.ErrNotFound) {
|
|
return ExitCodeNotFound
|
|
} else if errors.Is(err, gErrors.ErrDuplicateEntity) {
|
|
return ExitCodeDuplicate
|
|
}
|
|
return 1
|
|
}
|
|
return 0
|
|
}
|