aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTulir Asokan <tulir@maunium.net>2018-04-10 16:00:55 +0300
committerTulir Asokan <tulir@maunium.net>2018-04-10 16:01:01 +0300
commitb6e58e83a8ed74f3e0a5f7f0955d264febd542ce (patch)
tree37c2994aa3ed8c143e98c9c0176ed9be403553d0
parenteda2b575f06e72040ebf82d24a7ec1ac84b7948c (diff)
Include error in pretty panic log
-rw-r--r--debug/debug.go12
-rw-r--r--gomuks.go2
2 files changed, 10 insertions, 4 deletions
diff --git a/debug/debug.go b/debug/debug.go
index 9af3d9d..c6f367e 100644
--- a/debug/debug.go
+++ b/debug/debug.go
@@ -17,6 +17,7 @@
package debug
import (
+ "bytes"
"fmt"
"io"
"io/ioutil"
@@ -67,14 +68,18 @@ const Oops = ` __________
U ||----W |
|| ||`
-func PrettyPanic() {
+func PrettyPanic(panic interface{}) {
fmt.Println(Oops)
fmt.Println("")
fmt.Println("A fatal error has occurred.")
fmt.Println("")
traceFile := fmt.Sprintf("/tmp/gomuks-panic-%s.txt", time.Now().Format("2006-01-02--15-04-05"))
- data := debug.Stack()
- err := ioutil.WriteFile(traceFile, data, 0644)
+
+ var buf bytes.Buffer
+ fmt.Fprintln(&buf, panic)
+ buf.Write(debug.Stack())
+ err := ioutil.WriteFile(traceFile, buf.Bytes(), 0644)
+
if err != nil {
fmt.Println("Saving the stack trace to", traceFile, "failed:")
fmt.Println("--------------------------------------------------------------------------------")
@@ -85,6 +90,7 @@ func PrettyPanic() {
fmt.Println("Please provide the file save error (above) and the stack trace of the original error (below) when filing an issue.")
fmt.Println("")
fmt.Println("--------------------------------------------------------------------------------")
+ fmt.Println(panic)
debug.PrintStack()
fmt.Println("--------------------------------------------------------------------------------")
} else {
diff --git a/gomuks.go b/gomuks.go
index 5edae3a..494f182 100644
--- a/gomuks.go
+++ b/gomuks.go
@@ -117,7 +117,7 @@ func (gmx *Gomuks) Recover() {
if gmx.debugMode {
panic(p)
} else {
- debug.PrettyPanic()
+ debug.PrettyPanic(p)
}
}
}