mirror of
https://github.com/rwxrob/bonzai
synced 2024-11-14 18:12:59 +00:00
Add TrapPanic
This commit is contained in:
parent
3aea8cbeca
commit
6b76c5919f
@ -302,9 +302,10 @@ func ArgsOrIn(args []string) string {
|
||||
var Aliases = make(map[string][]string)
|
||||
|
||||
// TrapPanic recovers from any panic and more gracefully displays the
|
||||
// error as an exit message. Simply add defer TrapPanic() when wanted.
|
||||
// panic by logging it before exiting with a return value of 1.
|
||||
var TrapPanic = func() {
|
||||
if r := recover(); r != nil {
|
||||
ExitError(r)
|
||||
log.Println(r)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user