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>
This commit is contained in:
parent
e7f208367b
commit
80e8f6dc1e
2 changed files with 32 additions and 1 deletions
26
runner/providers/external/execution/exit_codes.go
vendored
Normal file
26
runner/providers/external/execution/exit_codes.go
vendored
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
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
|
||||
}
|
||||
7
runner/providers/external/external.go
vendored
7
runner/providers/external/external.go
vendored
|
|
@ -5,6 +5,7 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"os/exec"
|
||||
|
||||
"github.com/cloudbase/garm/config"
|
||||
garmErrors "github.com/cloudbase/garm/errors"
|
||||
|
|
@ -107,7 +108,11 @@ func (e *external) DeleteInstance(ctx context.Context, instance string) error {
|
|||
|
||||
_, err := garmExec.Exec(ctx, e.execPath, nil, asEnv)
|
||||
if err != nil {
|
||||
return garmErrors.NewProviderError("provider binary %s returned error: %s", e.execPath, err)
|
||||
var exitErr exec.ExitError
|
||||
if !errors.As(err, &exitErr) || exitErr.ExitCode() != execution.ExitCodeNotFound {
|
||||
return garmErrors.NewProviderError("provider binary %s returned error: %s", e.execPath, err)
|
||||
}
|
||||
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue