Include error in pretty panic log

This commit is contained in:
Tulir Asokan 2018-04-10 16:00:55 +03:00
parent eda2b575f0
commit b6e58e83a8
2 changed files with 10 additions and 4 deletions

View File

@ -17,6 +17,7 @@
package debug package debug
import ( import (
"bytes"
"fmt" "fmt"
"io" "io"
"io/ioutil" "io/ioutil"
@ -67,14 +68,18 @@ const Oops = ` __________
U ||----W | U ||----W |
|| ||` || ||`
func PrettyPanic() { func PrettyPanic(panic interface{}) {
fmt.Println(Oops) fmt.Println(Oops)
fmt.Println("") fmt.Println("")
fmt.Println("A fatal error has occurred.") fmt.Println("A fatal error has occurred.")
fmt.Println("") fmt.Println("")
traceFile := fmt.Sprintf("/tmp/gomuks-panic-%s.txt", time.Now().Format("2006-01-02--15-04-05")) 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 { if err != nil {
fmt.Println("Saving the stack trace to", traceFile, "failed:") fmt.Println("Saving the stack trace to", traceFile, "failed:")
fmt.Println("--------------------------------------------------------------------------------") 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("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("--------------------------------------------------------------------------------") fmt.Println("--------------------------------------------------------------------------------")
fmt.Println(panic)
debug.PrintStack() debug.PrintStack()
fmt.Println("--------------------------------------------------------------------------------") fmt.Println("--------------------------------------------------------------------------------")
} else { } else {

View File

@ -117,7 +117,7 @@ func (gmx *Gomuks) Recover() {
if gmx.debugMode { if gmx.debugMode {
panic(p) panic(p)
} else { } else {
debug.PrettyPanic() debug.PrettyPanic(p)
} }
} }
} }