Browse Source

commands: Run -> RunE

pull/442/head
Rigel Rozanski 8 years ago
committed by Ethan Buchman
parent
commit
5d0c2a1414
2 changed files with 14 additions and 11 deletions
  1. +4
    -4
      cmd/tendermint/commands/probe_upnp.go
  2. +10
    -7
      cmd/tendermint/commands/run_node.go

+ 4
- 4
cmd/tendermint/commands/probe_upnp.go View File

@ -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
}

+ 10
- 7
cmd/tendermint/commands/run_node.go View File

@ -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
}

Loading…
Cancel
Save