Merge pull request #274 from thockin/6-better-run-logs

Improve logs when running a command
This commit is contained in:
Kubernetes Prow Robot 2020-09-05 10:21:41 -07:00 committed by GitHub
commit 37f74f46fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 3 deletions

View File

@ -741,7 +741,8 @@ func runCommand(ctx context.Context, cwd, command string, args ...string) (strin
}
func runCommandWithStdin(ctx context.Context, cwd, stdin, command string, args ...string) (string, error) {
log.V(5).Info("running command", "cwd", cwd, "cmd", cmdForLog(command, args...))
cmdStr := cmdForLog(command, args...)
log.V(5).Info("running command", "cwd", cwd, "cmd", cmdStr)
cmd := exec.CommandContext(ctx, command, args...)
if cwd != "" {
@ -757,11 +758,12 @@ func runCommandWithStdin(ctx context.Context, cwd, stdin, command string, args .
stdout := outbuf.String()
stderr := errbuf.String()
if ctx.Err() == context.DeadlineExceeded {
return "", fmt.Errorf("command timed out: %v: { stdout: %q, stderr: %q }", err, stdout, stderr)
return "", fmt.Errorf("Run(%s): %w: { stdout: %q, stderr: %q }", cmdStr, ctx.Err(), stdout, stderr)
}
if err != nil {
return "", fmt.Errorf("error running command: %v: { stdout: %q, stderr: %q }", err, stdout, stderr)
return "", fmt.Errorf("Run(%s): %w: { stdout: %q, stderr: %q }", cmdStr, err, stdout, stderr)
}
log.V(6).Info("command result", "stdout", stdout, "stderr", stderr)
return stdout, nil
}