Merge pull request #1494 from gtardif/cancel_docker_cli_metrics

Track cancel exit code from docker cli shellout to report correct status in metrics
This commit is contained in:
Nicolas De loof 2021-04-06 14:35:04 +02:00 committed by GitHub
commit bd5c188be6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 2 deletions

View File

@ -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)
}