From 2ef79dc365b39f78ab415340f05b89da0421b616 Mon Sep 17 00:00:00 2001 From: Steve Kemp Date: Thu, 26 Jul 2018 06:59:37 +0300 Subject: [PATCH] Avoid panic() - instead output a human-readable message on failure --- cmd_metrics.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cmd_metrics.go b/cmd_metrics.go index 09523b7..cf99478 100644 --- a/cmd_metrics.go +++ b/cmd_metrics.go @@ -8,6 +8,7 @@ import ( "context" "flag" "fmt" + "os" "github.com/google/subcommands" "github.com/marpaia/graphite-golang" @@ -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. @@ -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 } //