From 8896293cba1cfc8d603781ef3c44ffe43784db72 Mon Sep 17 00:00:00 2001 From: deads2k Date: Tue, 29 Nov 2016 08:00:09 -0500 Subject: [PATCH] add stderr to command errors --- hack/e2e.go | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/hack/e2e.go b/hack/e2e.go index 6cf14d98a7c..e894b4ca757 100644 --- a/hack/e2e.go +++ b/hack/e2e.go @@ -584,7 +584,7 @@ func clusterSize(deploy deployer) (int, error) { } o, err := exec.Command("kubectl", "get", "nodes", "--no-headers").Output() if err != nil { - log.Printf("kubectl get nodes failed: %v", err) + log.Printf("kubectl get nodes failed: %s\n%s", WrapError(err).Error(), string(o)) return -1, err } stdout := strings.TrimSpace(string(o)) @@ -592,6 +592,35 @@ func clusterSize(deploy deployer) (int, error) { return len(strings.Split(stdout, "\n")), nil } +// CommandError will provide stderr output (if available) from structured +// exit errors +type CommandError struct { + err error +} + +func WrapError(err error) *CommandError { + if err == nil { + return nil + } + return &CommandError{err: err} +} + +func (e *CommandError) Error() string { + if e == nil { + return "" + } + exitErr, ok := e.err.(*exec.ExitError) + if !ok { + return e.err.Error() + } + + stderr := "" + if exitErr.Stderr != nil { + stderr = string(stderr) + } + return fmt.Sprintf("%q: %q", exitErr.Error(), stderr) +} + func DumpClusterLogs(location string) error { log.Printf("Dumping cluster logs to: %v", location) return finishRunning("dump cluster logs", exec.Command("./cluster/log-dump.sh", location))