From 9d0d88eacf0713ee769a63ba6c08c2df6567dced Mon Sep 17 00:00:00 2001 From: jankaspar <2270833+jankaspar@users.noreply.github.com> Date: Thu, 10 Sep 2020 11:04:23 +0100 Subject: [PATCH] Improve error codes for armadactl. (#427) --- cmd/armadactl/cmd/cancel.go | 3 +-- cmd/armadactl/cmd/createQueue.go | 6 ++---- cmd/armadactl/cmd/deleteQueue.go | 3 +-- cmd/armadactl/cmd/info.go | 3 +-- cmd/armadactl/cmd/root.go | 5 +++++ cmd/armadactl/cmd/submit.go | 6 ++---- 6 files changed, 12 insertions(+), 14 deletions(-) diff --git a/cmd/armadactl/cmd/cancel.go b/cmd/armadactl/cmd/cancel.go index c7712209d88..e4000c4831c 100644 --- a/cmd/armadactl/cmd/cancel.go +++ b/cmd/armadactl/cmd/cancel.go @@ -45,8 +45,7 @@ var cancelCmd = &cobra.Command{ Queue: queue, }) if e != nil { - log.Error(e) - return + exitWithError(e) } log.Infof("Cancellation request submitted for jobs: %s", strings.Join(result.CancelledIds, ", ")) }) diff --git a/cmd/armadactl/cmd/createQueue.go b/cmd/armadactl/cmd/createQueue.go index 8ce9506db34..4cf70df9d84 100644 --- a/cmd/armadactl/cmd/createQueue.go +++ b/cmd/armadactl/cmd/createQueue.go @@ -43,8 +43,7 @@ Job priority is evaluated inside queue, queue has its own priority.`, resourceLimits, _ := cmd.Flags().GetStringToString("resourceLimits") resourceLimitsFloat, err := convertResourceLimitsToFloat64(resourceLimits) if err != nil { - log.Error(err) - return + exitWithError(err) } apiConnectionDetails := client.ExtractCommandlineArmadaApiConnectionDetails() @@ -59,8 +58,7 @@ Job priority is evaluated inside queue, queue has its own priority.`, ResourceLimits: resourceLimitsFloat}) if e != nil { - log.Error(e) - return + exitWithError(e) } log.Infof("Queue %s created.", queue) }) diff --git a/cmd/armadactl/cmd/deleteQueue.go b/cmd/armadactl/cmd/deleteQueue.go index 49406b8bee7..6a5984ac4c6 100644 --- a/cmd/armadactl/cmd/deleteQueue.go +++ b/cmd/armadactl/cmd/deleteQueue.go @@ -28,8 +28,7 @@ var deleteQueueCmd = &cobra.Command{ submissionClient := api.NewSubmitClient(conn) e := client.DeleteQueue(submissionClient, queue) if e != nil { - log.Error(e) - return + exitWithError(e) } log.Infof("Queue %s deleted or did not exist.", queue) }) diff --git a/cmd/armadactl/cmd/info.go b/cmd/armadactl/cmd/info.go index 80741113bd9..b552b16c14d 100644 --- a/cmd/armadactl/cmd/info.go +++ b/cmd/armadactl/cmd/info.go @@ -34,8 +34,7 @@ var infoCmd = &cobra.Command{ defer cancel() queueInfo, e := submitClient.GetQueueInfo(ctx, &api.QueueInfoRequest{queue}) if e != nil { - log.Error(e) - return + exitWithError(e) } jobSets := queueInfo.ActiveJobSets diff --git a/cmd/armadactl/cmd/root.go b/cmd/armadactl/cmd/root.go index e035759023a..9b86d3b6c93 100644 --- a/cmd/armadactl/cmd/root.go +++ b/cmd/armadactl/cmd/root.go @@ -47,3 +47,8 @@ var cfgFile string func initConfig() { client.LoadCommandlineArgsFromConfigFile(cfgFile) } + +func exitWithError(e error) { + log.Error(e) + os.Exit(1) +} diff --git a/cmd/armadactl/cmd/submit.go b/cmd/armadactl/cmd/submit.go index 1f1b7edd43a..d5330120955 100644 --- a/cmd/armadactl/cmd/submit.go +++ b/cmd/armadactl/cmd/submit.go @@ -49,8 +49,7 @@ var submitCmd = &cobra.Command{ err = util.BindJsonOrYaml(filePath, submitFile) if err != nil { - log.Error(err) - os.Exit(1) + exitWithError(err) } if dryRun { @@ -67,8 +66,7 @@ var submitCmd = &cobra.Command{ response, e := client.SubmitJobs(submissionClient, request) if e != nil { - log.Error(e) - os.Exit(1) + exitWithError(e) } summariseResponse(response, request.JobSetId)