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() diff --git a/util.go b/util.go index b5cda5e..b03987c 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) } }