From 6465bfec82825f686aa6c36f5d3a5069b7f26715 Mon Sep 17 00:00:00 2001 From: Guillaume Tardif Date: Tue, 6 Apr 2021 10:19:27 +0200 Subject: [PATCH] track cancel exit code from docker cli shellout to report correct status in metrics Signed-off-by: Guillaume Tardif --- cli/mobycli/exec.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cli/mobycli/exec.go b/cli/mobycli/exec.go index 6a5e09dd..d710fdb2 100644 --- a/cli/mobycli/exec.go +++ b/cli/mobycli/exec.go @@ -66,11 +66,16 @@ func Exec(root *cobra.Command) { err := RunDocker(childExit, os.Args[1:]...) childExit <- true if err != nil { - metrics.Track(store.DefaultContextType, os.Args[1:], metrics.FailureStatus) - 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.FailureStatus) fmt.Fprintln(os.Stderr, err) os.Exit(1) }