-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpanic_handler.go
More file actions
28 lines (24 loc) · 754 Bytes
/
panic_handler.go
File metadata and controls
28 lines (24 loc) · 754 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Copyright 2024 The Mellium Contributors.
// Use of this source code is governed by the BSD 2-clause
// license that can be found in the LICENSE file.
package main
import (
"fmt"
"os"
"runtime/debug"
)
var uiShutdown = func() {}
// panicHandler should be deferred as the first thing in all goroutines started
// anywhere in the system.
// This will allow us to shut down and clean up the UI before printing the stack
// trace, thus averting a mess of text all over the screen.
// If we decide to save/send stack traces later this will also give us a central
// place to do that.
func panicHandler() {
if r := recover(); r != nil {
uiShutdown()
fmt.Fprintf(os.Stderr, "%s\n", debug.Stack())
fmt.Fprintln(os.Stderr, "----")
panic(r)
}
}