package cmd
import "errors"
// Sentinel errors recognized by Execute → exit code mapping.
//
// exists → ErrNotFound → 1
// download without --url/--exec, key missing → ErrMissNoFallback → 3
// --exec script failed → the script's own exit status
// any other error → 2
var (
ErrNotFound = errors.New("cacher: key not found")
ErrMissNoFallback = errors.New("cacher: cache miss and no --url/--exec fallback")
)
func exitCodeFor(err error) int {
// A failed --exec script reports its own status: the caller wrote
// that script and its exit code says more than a generic 2.
var coded interface{ ExitCode() int }
switch {
case err == nil:
return 0
case errors.Is(err, ErrNotFound):
return 1
case errors.Is(err, ErrMissNoFallback):
return 3
case errors.As(err, &coded):
return coded.ExitCode()
default:
return 2
}
}