From b17ff318c26aecdcf2c6719ed5b0872be5254c44 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Wed, 18 Apr 2018 18:35:24 +0300 Subject: Disconnect UI from main Gomuks struct. Fixes #21 --- debug/debug.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'debug') 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! > ‾‾‾\‾‾‾‾‾‾ -- cgit v1.2.3