mirror of
https://github.com/docker/compose.git
synced 2025-07-25 22:54:54 +02:00
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
@ -78,7 +78,7 @@ func runRemove(ctx context.Context, backend compose.Service, opts removeOptions,
|
|||||||
}
|
}
|
||||||
|
|
||||||
reosurces, err := backend.Remove(ctx, project, compose.RemoveOptions{
|
reosurces, err := backend.Remove(ctx, project, compose.RemoveOptions{
|
||||||
DryRun: true,
|
DryRun: true,
|
||||||
Services: services,
|
Services: services,
|
||||||
})
|
})
|
||||||
if err != nil {
|
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) {
|
_, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
|
||||||
return "", backend.Stop(ctx, project, compose.StopOptions{
|
return "", backend.Stop(ctx, project, compose.StopOptions{
|
||||||
Timeout: timeout,
|
Timeout: timeout,
|
||||||
Services: services,
|
Services: services,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -294,7 +294,7 @@ func exit(ctx string, err error, ctype string) {
|
|||||||
|
|
||||||
if errors.Is(err, errdefs.ErrNotImplemented) {
|
if errors.Is(err, errdefs.ErrNotImplemented) {
|
||||||
name := metrics.GetCommand(os.Args[1:])
|
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)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
@ -314,7 +314,7 @@ func checkIfUnknownCommandExistInDefaultContext(err error, currentContext string
|
|||||||
dockerCommand := string(submatch[1])
|
dockerCommand := string(submatch[1])
|
||||||
|
|
||||||
if mobycli.IsDefaultContextCommand(dockerCommand) {
|
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)
|
metrics.Track(contextType, os.Args[1:], metrics.FailureStatus)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
@ -55,3 +55,26 @@ var (
|
|||||||
// PullFailure failure while pulling image
|
// PullFailure failure while pulling image
|
||||||
PullFailure = FailureCategory{MetricsStatus: PullFailureStatus, ExitCode: 18}
|
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 err != nil {
|
||||||
if exiterr, ok := err.(*exec.ExitError); ok {
|
if exiterr, ok := err.(*exec.ExitError); ok {
|
||||||
exitCode := exiterr.ExitCode()
|
exitCode := exiterr.ExitCode()
|
||||||
if exitCode == 130 {
|
metrics.Track(store.DefaultContextType, os.Args[1:], metrics.ByExitCode(exitCode).MetricsStatus)
|
||||||
metrics.Track(store.DefaultContextType, os.Args[1:], metrics.CanceledStatus)
|
os.Exit(exitCode)
|
||||||
} else {
|
|
||||||
metrics.Track(store.DefaultContextType, os.Args[1:], metrics.FailureStatus)
|
|
||||||
}
|
|
||||||
os.Exit(exiterr.ExitCode())
|
|
||||||
}
|
}
|
||||||
metrics.Track(store.DefaultContextType, os.Args[1:], metrics.FailureStatus)
|
metrics.Track(store.DefaultContextType, os.Args[1:], metrics.FailureStatus)
|
||||||
fmt.Fprintln(os.Stderr, err)
|
fmt.Fprintln(os.Stderr, err)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user