From a8926aaab6e5f5fdbc5e3ff90ad7787596158c92 Mon Sep 17 00:00:00 2001 From: Martin Eskdale Moen Date: Mon, 7 Sep 2020 17:22:24 +0100 Subject: [PATCH 1/2] Include a custom message if there is an error This change lets us include a custom message if there is an error --- util.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/util.go b/util.go index 64fda9f..7d69f3c 100644 --- a/util.go +++ b/util.go @@ -7,8 +7,11 @@ import ( "strings" ) -func check(e error) { +func check(e error, optMsg ...string) { if e != nil { + if (len(optMsg) > 0) { + ExitFail("%s - %s", e, strings.Join(optMsg, " ")) + } ExitFail("%s", e) } } From 01d609e8598ff8ba9d60cceceb4509c0faddb979 Mon Sep 17 00:00:00 2001 From: Martin Eskdale Moen Date: Mon, 7 Sep 2020 20:21:57 +0100 Subject: [PATCH 2/2] If we can't connect to internet, fail --- init.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/init.go b/init.go index 79d0e0c..f3e7bda 100644 --- a/init.go +++ b/init.go @@ -56,7 +56,8 @@ func getRandomNetwork() JSONIPNet { // TODO support IPv6 func getExternalIP() net.IP { - conn, _ := net.Dial("udp", "8.8.8.8:80") + conn, err := net.Dial("udp", "8.8.8.8:80") + check(err, "Could not detect internet connection") defer conn.Close() localAddr := conn.LocalAddr().String()