Skip to content

Commit

Permalink
Avoid panic() - instead output a human-readable message on failure
Browse files Browse the repository at this point in the history
  • Loading branch information
skx committed Jul 26, 2018
1 parent e509461 commit 2ef79dc
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions cmd_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"context"
"flag"
"fmt"
"os"

"github.com/google/subcommands"
"github.com/marpaia/graphite-golang"
Expand All @@ -24,7 +25,8 @@ func getMetrics() map[string]string {
// Get the node-states.
data, err := getStates()
if err != nil {
panic(err)
fmt.Printf("Error getting node states: %s\n", err.Error())
os.Exit(1)
}

// Now record the metrics we would send.
Expand Down Expand Up @@ -60,7 +62,8 @@ func SendMetrics(host string, port int, prefix string, nop bool) {
// providing we are running in `-nop`-mode.
//
if (err != nil) && (nop == false) {
panic(err)
fmt.Printf("Error creating metrics-helper: %s\n", err.Error())
return
}

//
Expand Down

0 comments on commit 2ef79dc

Please sign in to comment.