From dff61820a1f5663513361c04656f0f867c8b6414 Mon Sep 17 00:00:00 2001 From: "Sean E. Russell" Date: Wed, 10 Aug 2022 15:32:26 -0500 Subject: [PATCH] Minimally addresses #71: don't swallow errors. Also return the right exit error code when errors are encountered. --- cmd/root.go | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 7e7f45e..b96a539 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -3,6 +3,7 @@ package main import ( "errors" "fmt" + "os" "strings" "time" @@ -15,9 +16,10 @@ import ( var ( // Flags. - owner string - description string - confirm bool + owner string + description string + confirm bool + error_encountered bool // Commands. rootCmd = &cobra.Command{} @@ -39,8 +41,14 @@ var ( Run: func(cmd *cobra.Command, args []string) { config := cli.MustLoadConfigFile() server := cli.GetServer(config) - server.Up() - utils.ShellOut(config.PostUp, "PostUp") + if e := server.Up(); e != nil { + fmt.Printf("error bringing up the network: %s\n", e) + error_encountered = true + } + if e := utils.ShellOut(config.PostUp, "PostUp"); e != nil { + fmt.Printf("error bringing up the network: %s\n", e) + error_encountered = true + } }, } @@ -50,8 +58,14 @@ var ( Run: func(cmd *cobra.Command, args []string) { config := cli.MustLoadConfigFile() server := cli.GetServer(config) - server.DeleteLink() - utils.ShellOut(config.PostDown, "PostDown") + if e := server.DeleteLink(); e != nil { + fmt.Printf("error bringing up the network: %s\n", e) + error_encountered = true + } + if e := utils.ShellOut(config.PostDown, "PostDown"); e != nil { + fmt.Printf("error bringing up the network: %s\n", e) + error_encountered = true + } }, } @@ -169,4 +183,8 @@ func main() { if err := rootCmd.Execute(); err != nil { cli.ExitFail(err.Error()) } + if error_encountered { + os.Exit(1) + } + os.Exit(0) }