From 0163fa6f11b2125d0abc01438e4ae2caa64b29c7 Mon Sep 17 00:00:00 2001 From: zimbatm Date: Fri, 8 Nov 2024 19:22:30 +0100 Subject: [PATCH] fix: expose cleanup errors If anything fails during the cleanup, expose the error to the end-user by changing the exit status. --- command/cleanup.go | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/command/cleanup.go b/command/cleanup.go index 2e84118..f0aa202 100644 --- a/command/cleanup.go +++ b/command/cleanup.go @@ -64,9 +64,18 @@ func CmdCleanup(c *cli.Context) (err error) { log.Println("to undeploy:", toUndeploy) + var lastErr error + for _, name := range toUndeploy { log.Println("Undeploying", name) + pullRequestID, err := strconv.Atoi(name) + if err != nil { + log.Println("Unable to parse pull request id: ", name) + lastErr = err + continue + } + cmd := exec.Command(c.Args().Get(0), c.Args()[1:]...) //#nosec cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr @@ -74,21 +83,14 @@ func CmdCleanup(c *cli.Context) (err error) { err = cmd.Run() if err != nil { log.Println("undeploy error: ", err) - - continue - } - - pullRequestID, err := strconv.Atoi(name) - if err != nil { - log.Println("Unable to parse pull request id: ", name) - + lastErr = err continue } destroyGitHubDeployments(ctx, ghCli, owner, repo, pullRequestID, ignoreMissing) } - return nil + return lastErr } func contains(item string, list []string) bool {