Skip to content

Commit

Permalink
dexc: recover and log panic in main
Browse files Browse the repository at this point in the history
  • Loading branch information
chappjc committed Feb 3, 2022
1 parent c8081b7 commit 8e22b7f
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion client/cmd/dexc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"os"
"os/signal"
"runtime"
"runtime/debug"
"runtime/pprof"
"strings"
"sync"
Expand Down Expand Up @@ -80,6 +81,14 @@ func mainCore() error {
time.Now().Local().Format("15:04:05 MST"))
}

defer func() {
if pv := recover(); pv != nil {
log.Criticalf("Uh-oh! \n\nPanic:\n\n%v\n\nStack:\n\n%v\n\n",
pv, string(debug.Stack()))
}
closeFileLogger()
}()

// Prepare the Core.
clientCore, err := core.New(&core.Config{
DBPath: cfg.DBPath, // global set in config.go
Expand Down Expand Up @@ -121,7 +130,6 @@ func mainCore() error {
log.Info("Exiting dexc main.")
cancel() // no-op with clean rpc/web server setup
wg.Wait() // no-op with clean setup and shutdown
closeFileLogger()
}()

if cfg.RPCOn {
Expand Down

0 comments on commit 8e22b7f

Please sign in to comment.