From 5a789fca4a89ae3b184c3c4fe6dba79d780b6358 Mon Sep 17 00:00:00 2001 From: Alex Nebotov <46927280+skillful-alex@users.noreply.github.com> Date: Wed, 6 Nov 2019 19:18:51 +0300 Subject: [PATCH] Added the panic capture so that information about panic gets into the log file (#3877) * Added the panic capture so that information about it gets into the log file * Printf -> Errorf * Update validator/main.go "run time" -> "Runtime" Co-Authored-By: Raul Jordan * Update beacon-chain/main.go "run time" -> "Runtime" Co-Authored-By: Raul Jordan --- beacon-chain/main.go | 8 ++++++++ validator/main.go | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/beacon-chain/main.go b/beacon-chain/main.go index 57f0a13d6..edf90e23f 100644 --- a/beacon-chain/main.go +++ b/beacon-chain/main.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "runtime" + runtimeDebug "runtime/debug" golog "github.com/ipfs/go-log" joonix "github.com/joonix/log" @@ -123,6 +124,13 @@ func main() { return debug.Setup(ctx) } + defer func() { + if x := recover(); x != nil { + log.Errorf("Runtime panic: %v\n%v", x, string(runtimeDebug.Stack())) + panic(x) + } + }() + if err := app.Run(os.Args); err != nil { log.Error(err.Error()) os.Exit(1) diff --git a/validator/main.go b/validator/main.go index 6bc5bc320..5d4a642b0 100644 --- a/validator/main.go +++ b/validator/main.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "runtime" + runtimeDebug "runtime/debug" joonix "github.com/joonix/log" "github.com/prysmaticlabs/prysm/shared/cmd" @@ -152,6 +153,13 @@ contract in order to activate the validator client`, return nil } + defer func() { + if x := recover(); x != nil { + log.Errorf("Runtime panic: %v\n%v", x, string(runtimeDebug.Stack())) + panic(x) + } + }() + if err := app.Run(os.Args); err != nil { log.Error(err.Error()) os.Exit(1)