garm/runner/providers/external/execution/exit_codes.go
Gabriel Adrian Samfira 80e8f6dc1e
Add some exit codes
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>
2023-03-26 22:31:55 +03:00

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
}