Show error stack trace if --debug is set

We use github.com/pkg/errors to produce an error in many places.
One of its benefits is error comes with a stack trace.

Let's print that stack trace if --debug is set.

Example:

	# ../runc --debug run -d ''
	ERRO[0000] container id cannot be empty
	DEBU[0000] container id cannot be empty
	main.init
		github.com/opencontainers/runc/utils_linux.go:28
	runtime.doInit
		runtime/proc.go:5652
	runtime.main
		runtime/proc.go:191
	runtime.goexit
		runtime/asm_amd64.s:1374

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin
2021-02-04 11:45:29 -08:00
parent 19437f3a55
commit 1e0016cf57
+2
View File
@@ -55,6 +55,8 @@ func logrusToStderr() bool {
func fatal(err error) {
// make sure the error is written to the logger
logrus.Error(err)
// If debug is enabled and pkg/errors was used, show its stack trace.
logrus.Debugf("%+v", err)
if !logrusToStderr() {
fmt.Fprintln(os.Stderr, err)
}