Skip to content

Commit

Permalink
Minimally addresses #71: don't swallow errors.
Browse files Browse the repository at this point in the history
Also return the right exit error code when errors are encountered.
  • Loading branch information
xxxserxxx authored and botto committed Sep 12, 2022
1 parent 685ae16 commit dff6182
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"errors"
"fmt"
"os"
"strings"
"time"

Expand All @@ -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{}
Expand All @@ -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
}
},
}

Expand All @@ -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
}
},
}

Expand Down Expand Up @@ -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)
}

0 comments on commit dff6182

Please # to comment.