diff options
author | Tulir Asokan <tulir@maunium.net> | 2018-04-18 18:35:24 +0300 |
---|---|---|
committer | Tulir Asokan <tulir@maunium.net> | 2018-04-18 18:35:54 +0300 |
commit | b17ff318c26aecdcf2c6719ed5b0872be5254c44 (patch) | |
tree | 43f5f9aa3ce300c15376860727ff13d3716f3751 /debug | |
parent | 3b2d5fa0349bf01217f6954813c669680cdd16d4 (diff) |
Disconnect UI from main Gomuks struct. Fixes #21
Diffstat (limited to 'debug')
-rw-r--r-- | debug/debug.go | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/debug/debug.go b/debug/debug.go index c6f367e..3e32125 100644 --- a/debug/debug.go +++ b/debug/debug.go @@ -29,6 +29,8 @@ import ( ) var writer io.Writer +var RecoverPrettyPanic bool +var OnRecover func() func init() { var err error @@ -59,6 +61,22 @@ func PrintStack() { } } +// Recover recovers a panic, runs the OnRecover handler and either re-panics or +// shows an user-friendly message about the panic depending on whether or not +// the pretty panic mode is enabled. +func Recover() { + if p := recover(); p != nil { + if OnRecover != nil { + OnRecover() + } + if RecoverPrettyPanic { + PrettyPanic(p) + } else { + panic(p) + } + } +} + const Oops = ` __________ < Oh noes! > ‾‾‾\‾‾‾‾‾‾ |