From c78e1b98cccdfe1e83dddabdc95b849d2ef7aac2 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Mon, 10 Dec 2018 11:29:42 +0000 Subject: [PATCH] Show yggdrasilctl log buffer on panic --- cmd/yggdrasilctl/main.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cmd/yggdrasilctl/main.go b/cmd/yggdrasilctl/main.go index 9646f6c1..b37c2561 100644 --- a/cmd/yggdrasilctl/main.go +++ b/cmd/yggdrasilctl/main.go @@ -26,6 +26,13 @@ type admin_info map[string]interface{} func main() { logbuffer := &bytes.Buffer{} logger := log.New(logbuffer, "", log.Flags()) + defer func() { + if r := recover(); r != nil { + logger.Println("Fatal error:", r) + fmt.Print(logbuffer) + os.Exit(1) + } + }() endpoint := defaults.GetDefaults().DefaultAdminListen @@ -102,7 +109,6 @@ func main() { conn, err = net.Dial("tcp", endpoint) } if err != nil { - fmt.Print(logbuffer) panic(err) } logger.Println("Connected") @@ -137,7 +143,6 @@ func main() { } if err := encoder.Encode(&send); err != nil { - fmt.Print(logbuffer) panic(err) } logger.Printf("Request sent")