2018-02-08 05:55:53 +00:00
|
|
|
package pkgerrors
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
StackSourceFileName = "source"
|
|
|
|
StackSourceLineName = "line"
|
|
|
|
StackSourceFunctionName = "func"
|
|
|
|
)
|
|
|
|
|
|
|
|
// MarshalStack implements pkg/errors stack trace marshaling.
|
|
|
|
//
|
|
|
|
// zerolog.ErrorStackMarshaler = MarshalStack
|
2019-01-02 19:12:56 +00:00
|
|
|
func MarshalStack(err error) interface{} {
|
2018-02-08 05:55:53 +00:00
|
|
|
type stackTracer interface {
|
|
|
|
StackTrace() errors.StackTrace
|
|
|
|
}
|
|
|
|
var st errors.StackTrace
|
|
|
|
if err, ok := err.(stackTracer); ok {
|
|
|
|
st = err.StackTrace()
|
|
|
|
} else {
|
|
|
|
return nil
|
|
|
|
}
|
2019-01-02 19:12:56 +00:00
|
|
|
out := make([]map[string]string, 0, len(st))
|
|
|
|
for _, frame := range st {
|
|
|
|
out = append(out, map[string]string{
|
|
|
|
StackSourceFileName: fmt.Sprintf("%s", frame),
|
|
|
|
StackSourceLineName: fmt.Sprintf("%d", frame),
|
|
|
|
StackSourceFunctionName: fmt.Sprintf("%n", frame),
|
|
|
|
})
|
2018-02-08 05:55:53 +00:00
|
|
|
}
|
2019-01-02 19:12:56 +00:00
|
|
|
return out
|
2018-02-08 05:55:53 +00:00
|
|
|
}
|