mirror of https://github.com/docker/compose.git
Retrieve compose failure category by exit code
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
d8aa00a766
commit
db38d1244c
cli
|
@ -78,7 +78,7 @@ func runRemove(ctx context.Context, backend compose.Service, opts removeOptions,
|
|||
}
|
||||
|
||||
reosurces, err := backend.Remove(ctx, project, compose.RemoveOptions{
|
||||
DryRun: true,
|
||||
DryRun: true,
|
||||
Services: services,
|
||||
})
|
||||
if err != nil {
|
||||
|
|
|
@ -65,7 +65,7 @@ func runStop(ctx context.Context, backend compose.Service, opts stopOptions, ser
|
|||
}
|
||||
_, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
|
||||
return "", backend.Stop(ctx, project, compose.StopOptions{
|
||||
Timeout: timeout,
|
||||
Timeout: timeout,
|
||||
Services: services,
|
||||
})
|
||||
})
|
||||
|
|
|
@ -294,7 +294,7 @@ func exit(ctx string, err error, ctype string) {
|
|||
|
||||
if errors.Is(err, errdefs.ErrNotImplemented) {
|
||||
name := metrics.GetCommand(os.Args[1:])
|
||||
fmt.Fprintf(os.Stderr, "RootCommand %q not available in current context (%s)\n", name, ctx)
|
||||
fmt.Fprintf(os.Stderr, "Command %q not available in current context (%s)\n", name, ctx)
|
||||
|
||||
os.Exit(1)
|
||||
}
|
||||
|
@ -314,7 +314,7 @@ func checkIfUnknownCommandExistInDefaultContext(err error, currentContext string
|
|||
dockerCommand := string(submatch[1])
|
||||
|
||||
if mobycli.IsDefaultContextCommand(dockerCommand) {
|
||||
fmt.Fprintf(os.Stderr, "RootCommand %q not available in current context (%s), you can use the \"default\" context to run this command\n", dockerCommand, currentContext)
|
||||
fmt.Fprintf(os.Stderr, "Command %q not available in current context (%s), you can use the \"default\" context to run this command\n", dockerCommand, currentContext)
|
||||
metrics.Track(contextType, os.Args[1:], metrics.FailureStatus)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
|
|
@ -55,3 +55,26 @@ var (
|
|||
// PullFailure failure while pulling image
|
||||
PullFailure = FailureCategory{MetricsStatus: PullFailureStatus, ExitCode: 18}
|
||||
)
|
||||
|
||||
//ByExitCode retrieve FailureCategory based on command exit code
|
||||
func ByExitCode(exitCode int) FailureCategory {
|
||||
switch exitCode {
|
||||
case 0:
|
||||
return FailureCategory{MetricsStatus: SuccessStatus, ExitCode: 0}
|
||||
case 14:
|
||||
return FileNotFoundFailure
|
||||
case 15:
|
||||
return ComposeParseFailure
|
||||
case 16:
|
||||
return CommandSyntaxFailure
|
||||
case 17:
|
||||
return BuildFailure
|
||||
case 18:
|
||||
return PullFailure
|
||||
case 130:
|
||||
return FailureCategory{MetricsStatus: CanceledStatus, ExitCode: exitCode}
|
||||
default:
|
||||
return FailureCategory{MetricsStatus: FailureStatus, ExitCode: exitCode}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -68,12 +68,8 @@ func Exec(root *cobra.Command) {
|
|||
if err != nil {
|
||||
if exiterr, ok := err.(*exec.ExitError); ok {
|
||||
exitCode := exiterr.ExitCode()
|
||||
if exitCode == 130 {
|
||||
metrics.Track(store.DefaultContextType, os.Args[1:], metrics.CanceledStatus)
|
||||
} else {
|
||||
metrics.Track(store.DefaultContextType, os.Args[1:], metrics.FailureStatus)
|
||||
}
|
||||
os.Exit(exiterr.ExitCode())
|
||||
metrics.Track(store.DefaultContextType, os.Args[1:], metrics.ByExitCode(exitCode).MetricsStatus)
|
||||
os.Exit(exitCode)
|
||||
}
|
||||
metrics.Track(store.DefaultContextType, os.Args[1:], metrics.FailureStatus)
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
|
|
Loading…
Reference in New Issue