From 7480650e0524cc9966cac8d68a548d01464bd0d2 Mon Sep 17 00:00:00 2001 From: Ibrahim Mbaziira Date: Tue, 16 Oct 2018 23:37:27 +0300 Subject: [PATCH] Remove error output from stdout to stderr --- .../pkg/genericclioptions/printers/jsonpath.go | 10 ++++++---- test/cmd/get.sh | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/staging/src/k8s.io/cli-runtime/pkg/genericclioptions/printers/jsonpath.go b/staging/src/k8s.io/cli-runtime/pkg/genericclioptions/printers/jsonpath.go index 0bdb3511f1..333b9c3344 100644 --- a/staging/src/k8s.io/cli-runtime/pkg/genericclioptions/printers/jsonpath.go +++ b/staging/src/k8s.io/cli-runtime/pkg/genericclioptions/printers/jsonpath.go @@ -17,6 +17,7 @@ limitations under the License. package printers import ( + "bytes" "encoding/json" "fmt" "io" @@ -136,10 +137,11 @@ func (j *JSONPathPrinter) PrintObj(obj runtime.Object, w io.Writer) error { } if err := j.JSONPath.Execute(w, queryObj); err != nil { - fmt.Fprintf(w, "Error executing template: %v. Printing more information for debugging the template:\n", err) - fmt.Fprintf(w, "\ttemplate was:\n\t\t%v\n", j.rawTemplate) - fmt.Fprintf(w, "\tobject given to jsonpath engine was:\n\t\t%#v\n\n", queryObj) - return fmt.Errorf("error executing jsonpath %q: %v\n", j.rawTemplate, err) + buf := bytes.NewBuffer(nil) + fmt.Fprintf(buf, "Error executing template: %v. Printing more information for debugging the template:\n", err) + fmt.Fprintf(buf, "\ttemplate was:\n\t\t%v\n", j.rawTemplate) + fmt.Fprintf(buf, "\tobject given to jsonpath engine was:\n\t\t%#v\n\n", queryObj) + return fmt.Errorf("error executing jsonpath %q: %v\n", j.rawTemplate, buf.String()) } return nil } diff --git a/test/cmd/get.sh b/test/cmd/get.sh index 089e5aa4e5..a898174800 100755 --- a/test/cmd/get.sh +++ b/test/cmd/get.sh @@ -162,7 +162,7 @@ run_kubectl_get_tests() { kube::test::if_has_string "${output_message}" 'valid-pod:' ## check --allow-missing-template-keys=false results in an error for a missing key with jsonpath - output_message=$(! kubectl get pod valid-pod --allow-missing-template-keys=false -o jsonpath='{.missing}' "${kube_flags[@]}") + output_message=$(! kubectl get pod valid-pod --allow-missing-template-keys=false -o jsonpath='{.missing}' 2>&1 "${kube_flags[@]}") kube::test::if_has_string "${output_message}" 'missing is not found' ## check --allow-missing-template-keys=false results in an error for a missing key with go