From 5d0c2a1414c976ed29163e50569cfdbcefc4b0db Mon Sep 17 00:00:00 2001 From: Rigel Rozanski Date: Sat, 15 Apr 2017 16:40:52 -0400 Subject: [PATCH] commands: Run -> RunE --- cmd/tendermint/commands/probe_upnp.go | 8 ++++---- cmd/tendermint/commands/run_node.go | 17 ++++++++++------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/cmd/tendermint/commands/probe_upnp.go b/cmd/tendermint/commands/probe_upnp.go index eb55d6690..330dcf17d 100644 --- a/cmd/tendermint/commands/probe_upnp.go +++ b/cmd/tendermint/commands/probe_upnp.go @@ -12,14 +12,14 @@ import ( var probeUpnpCmd = &cobra.Command{ Use: "probe_upnp", Short: "Test UPnP functionality", - Run: probeUpnp, + RunE: probeUpnp, } func init() { RootCmd.AddCommand(probeUpnpCmd) } -func probeUpnp(cmd *cobra.Command, args []string) { +func probeUpnp(cmd *cobra.Command, args []string) error { capabilities, err := upnp.Probe() if err != nil { @@ -28,9 +28,9 @@ func probeUpnp(cmd *cobra.Command, args []string) { fmt.Println("Probe success!") jsonBytes, err := json.Marshal(capabilities) if err != nil { - panic(err) + return err } fmt.Println(string(jsonBytes)) } - + return nil } diff --git a/cmd/tendermint/commands/run_node.go b/cmd/tendermint/commands/run_node.go index 5e0fef32c..972ed5215 100644 --- a/cmd/tendermint/commands/run_node.go +++ b/cmd/tendermint/commands/run_node.go @@ -1,6 +1,7 @@ package commands import ( + "fmt" "io/ioutil" "time" @@ -13,9 +14,9 @@ import ( var runNodeCmd = &cobra.Command{ Use: "node", - Short: "Run the tendermint node", + Short: "RunE the tendermint node", PreRun: setConfigFlags, - Run: runNode, + RunE: runNode, } //flags @@ -82,7 +83,7 @@ func setConfigFlags(cmd *cobra.Command, args []string) { // should import github.com/tendermint/tendermint/node and implement // their own run_node to call node.NewNode (instead of node.NewNodeDefault) // with their custom priv validator and/or custom proxy.ClientCreator -func runNode(cmd *cobra.Command, args []string) { +func runNode(cmd *cobra.Command, args []string) error { // Wait until the genesis doc becomes available // This is for Mintnet compatibility. @@ -98,14 +99,14 @@ func runNode(cmd *cobra.Command, args []string) { } jsonBlob, err := ioutil.ReadFile(genDocFile) if err != nil { - Exit(Fmt("Couldn't read GenesisDoc file: %v", err)) + return fmt.Errorf("Couldn't read GenesisDoc file: %v", err) } genDoc, err := types.GenesisDocFromJSON(jsonBlob) if err != nil { - Exit(Fmt("Error reading GenesisDoc: %v", err)) + return fmt.Errorf("Error reading GenesisDoc: %v", err) } if genDoc.ChainID == "" { - Exit(Fmt("Genesis doc %v must include non-empty chain_id", genDocFile)) + return fmt.Errorf("Genesis doc %v must include non-empty chain_id", genDocFile) } config.Set("chain_id", genDoc.ChainID) } @@ -114,11 +115,13 @@ func runNode(cmd *cobra.Command, args []string) { // Create & start node n := node.NewNodeDefault(config) if _, err := n.Start(); err != nil { - Exit(Fmt("Failed to start node: %v", err)) + return fmt.Errorf("Failed to start node: %v", err) } else { log.Notice("Started node", "nodeInfo", n.Switch().NodeInfo()) } // Trap signal, run forever. n.RunForever() + + return nil }