From 1e0016cf576b6a4f26686be4a6f0bdd229d3402b Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Thu, 4 Feb 2021 11:45:29 -0800 Subject: [PATCH] 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 --- utils.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/utils.go b/utils.go index 8b31be03f..85413c291 100644 --- a/utils.go +++ b/utils.go @@ -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) }