From 9b980d136fb1e738b8a464baba15c305f24fb56b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Han?= Date: Wed, 7 Oct 2020 14:45:04 +0200 Subject: [PATCH] ceph: log stderr in error when exec with output file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In order to properly debug errors, we need to merge stderr inside the `err` reported so that we don't only see the stdout. We were doing this when executing without file output, doing the same for the output file. Signed-off-by: Sébastien Han --- pkg/util/exec/exec.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/util/exec/exec.go b/pkg/util/exec/exec.go index 2fdef2c41..ae87a9485 100644 --- a/pkg/util/exec/exec.go +++ b/pkg/util/exec/exec.go @@ -199,6 +199,9 @@ func (*CommandExecutor) ExecuteCommandWithOutputFile(command, outfileArg string, // #nosec G204 Rook controls the input to the exec arguments cmd := exec.Command(command, arg...) cmdOut, err := cmd.CombinedOutput() + if err != nil { + cmdOut = []byte(fmt.Sprintf("%s. %s", string(cmdOut), string(err.(*exec.ExitError).Stderr))) + } // if there was anything that went to stdout/stderr then log it, even before we return an error if string(cmdOut) != "" { logger.Debug(string(cmdOut))