Remove error output from stdout to stderr

This commit is contained in:
Ibrahim Mbaziira 2018-10-16 23:37:27 +03:00
parent 2a733afaee
commit 7480650e05
No known key found for this signature in database
GPG Key ID: AD2F94CDEA5F7863
2 changed files with 7 additions and 5 deletions

View File

@ -17,6 +17,7 @@ limitations under the License.
package printers package printers
import ( import (
"bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "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 { 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) buf := bytes.NewBuffer(nil)
fmt.Fprintf(w, "\ttemplate was:\n\t\t%v\n", j.rawTemplate) fmt.Fprintf(buf, "Error executing template: %v. Printing more information for debugging the template:\n", err)
fmt.Fprintf(w, "\tobject given to jsonpath engine was:\n\t\t%#v\n\n", queryObj) fmt.Fprintf(buf, "\ttemplate was:\n\t\t%v\n", j.rawTemplate)
return fmt.Errorf("error executing jsonpath %q: %v\n", j.rawTemplate, err) 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 return nil
} }

View File

@ -162,7 +162,7 @@ run_kubectl_get_tests() {
kube::test::if_has_string "${output_message}" 'valid-pod:' 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 ## 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' 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 ## check --allow-missing-template-keys=false results in an error for a missing key with go