mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-25 13:07:17 +00:00
save (#124)
This commit is contained in:
parent
ec0155d4ed
commit
505bf97249
@ -1,32 +1,10 @@
|
||||
package dbg
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
stack2 "github.com/go-stack/stack"
|
||||
)
|
||||
|
||||
func StackInLogsFormat() string {
|
||||
// Stack returns stack-trace in logger-friendly compact formatting
|
||||
func Stack() string {
|
||||
return stack2.Trace().TrimBelow(stack2.Caller(1)).String()
|
||||
}
|
||||
|
||||
// Recover - does save panic to datadir/crashreports, bud doesn't log to logger and doesn't stop the process
|
||||
// it returns recovered panic as error in format friendly for our logger
|
||||
// common pattern of use - assign to named output param:
|
||||
// func A() (err error) {
|
||||
// defer func() { err = debug.Recover(err) }() // avoid crash because Erigon's core does many things
|
||||
// }
|
||||
func Recover(err error) error {
|
||||
panicResult := recover()
|
||||
if panicResult == nil {
|
||||
return err
|
||||
}
|
||||
|
||||
switch typed := panicResult.(type) {
|
||||
case error:
|
||||
err = fmt.Errorf("%w, trace: %s", typed, StackInLogsFormat())
|
||||
default:
|
||||
err = fmt.Errorf("%+v, trace: %s", typed, StackInLogsFormat())
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
@ -207,7 +207,7 @@ func (f *Fetch) receiveMessage(ctx context.Context, sentryClient sentry.SentryCl
|
||||
func (f *Fetch) handleInboundMessage(ctx context.Context, req *sentry.InboundMessage, sentryClient sentry.SentryClient) (err error) {
|
||||
defer func() {
|
||||
if rec := recover(); rec != nil {
|
||||
err = fmt.Errorf("%+v, trace: %s", rec, dbg.StackInLogsFormat())
|
||||
err = fmt.Errorf("%+v, trace: %s, rlp: %x", rec, dbg.Stack(), req.Data)
|
||||
}
|
||||
}()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user