Skip to content

Commit f9953c1

Browse files
committed
Output the stack error as an actual array
This just makes debugging of stacks easier.
1 parent 6500d4d commit f9953c1

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

‎pkg/util/runtime/runtime.go‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,30 @@
1717
package runtime
1818

1919
import (
20+
"fmt"
21+
22+
"github.com/pkg/errors"
2023
"github.com/sirupsen/logrus"
2124
"k8s.io/apimachinery/pkg/util/runtime"
2225
)
2326

27+
// stackTracer is the pkg/errors stacktrace interface
28+
type stackTracer interface {
29+
StackTrace() errors.StackTrace
30+
}
31+
2432
// replace the standard glog error logger, with a logrus one
2533
func init() {
2634
runtime.ErrorHandlers[0] = func(err error) {
27-
logrus.Errorf("stack: %+v", err)
35+
if err, ok := err.(stackTracer); ok {
36+
var stack []string
37+
for _, f := range err.StackTrace() {
38+
stack = append(stack, fmt.Sprintf("%+v", f))
39+
}
40+
logrus.WithField("stack", stack).Error(err)
41+
} else {
42+
logrus.Error(err)
43+
}
2844
}
2945
}
3046

0 commit comments

Comments
 (0)