prysm-pulse/shared/traceutil/recovery_interceptor_option.go
Preston Van Loon 4e22f52ab3 Testnet restart and hotfixes (#3736)
* hotfix for round robin, hotfix for grpc recovery

* gofmt

* break

* wrong subtraction

* lint

* testnet fork version update

* ignore relay / DHT protocol not supported error
2019-10-08 07:59:08 +08:00

23 lines
635 B
Go

package traceutil
import (
"context"
"errors"
"runtime/debug"
"github.com/sirupsen/logrus"
"go.opencensus.io/trace"
)
// RecoveryHandlerFunc is a function that recovers from the panic `p` by returning an `error`.
// The context can be used to extract request scoped metadata and context values.
func RecoveryHandlerFunc(ctx context.Context, p interface{}) error {
span := trace.FromContext(ctx)
if span != nil {
span.AddAttributes(trace.StringAttribute("stack", string(debug.Stack())))
}
err := errors.New(p.(string))
logrus.WithError(err).WithField("stack", string(debug.Stack())).Error("gRPC panicked!")
return err
}