aboutsummaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
authorTulir Asokan <tulir@maunium.net>2018-03-19 01:18:36 +0200
committerTulir Asokan <tulir@maunium.net>2018-03-19 01:21:53 +0200
commit7a4b108b37ccf415f75d74738dddbdba23af1805 (patch)
treec24add86e6e6f489ef9e05bf9a5463463613fa12 /ui
parentf288a18a0c0ea2609667a02ebe42ca0a8b034004 (diff)
Avoid showing panics directly if debug mode is not enabled
Diffstat (limited to 'ui')
-rw-r--r--ui/debug/debug.go49
-rw-r--r--ui/view-main.go4
2 files changed, 49 insertions, 4 deletions
diff --git a/ui/debug/debug.go b/ui/debug/debug.go
index c855897..a87d64c 100644
--- a/ui/debug/debug.go
+++ b/ui/debug/debug.go
@@ -18,6 +18,11 @@ package debug
import (
"fmt"
+ "io/ioutil"
+ "os"
+ "time"
+
+ "runtime/debug"
"maunium.net/go/tview"
)
@@ -30,7 +35,7 @@ type Printer interface {
type Pane struct {
*tview.TextView
Height int
- num int
+ num int
}
var Default Printer
@@ -46,8 +51,8 @@ func NewPane() *Pane {
return &Pane{
TextView: pane,
- Height: 35,
- num: 0,
+ Height: 35,
+ num: 0,
}
}
@@ -81,3 +86,41 @@ func Print(text ...interface{}) {
Default.Print(text...)
}
}
+
+const Oops = ` __________
+< Oh noes! >
+ ‾‾‾\‾‾‾‾‾‾
+ \ ^__^
+ \ (XX)\_______
+ (__)\ )\/\
+ U ||----W |
+ || ||`
+
+func PrettyPanic() {
+ 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)
+ if err != nil {
+ fmt.Println("Saving the stack trace to", traceFile, "failed:")
+ fmt.Println("--------------------------------------------------------------------------------")
+ fmt.Println(err)
+ fmt.Println("--------------------------------------------------------------------------------")
+ fmt.Println("")
+ fmt.Println("You can file an issue at https://github.com/tulir/gomuks/issues.")
+ 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("--------------------------------------------------------------------------------")
+ debug.PrintStack()
+ fmt.Println("--------------------------------------------------------------------------------")
+ } else {
+ fmt.Println("The stack trace has been saved to", traceFile)
+ fmt.Println("")
+ fmt.Println("You can file an issue at https://github.com/tulir/gomuks/issues.")
+ fmt.Println("Please provide the contents of that file when filing an issue.")
+ }
+ os.Exit(1)
+}
diff --git a/ui/view-main.go b/ui/view-main.go
index 8ec482e..c2cd30f 100644
--- a/ui/view-main.go
+++ b/ui/view-main.go
@@ -148,7 +148,7 @@ func (view *MainView) InputDone(key tcell.Key) {
}
func (view *MainView) HandleCommand(room, command string, args []string) {
- view.gmx.Recover()
+ defer view.gmx.Recover()
debug.Print("Handling command", command, args)
switch command {
case "/quit":
@@ -156,6 +156,8 @@ func (view *MainView) HandleCommand(room, command string, args []string) {
case "/clearcache":
view.config.Session.Clear()
view.gmx.Stop()
+ case "/panic":
+ panic("This is a test panic.")
case "/part":
fallthrough
case "/leave":