diff --git a/pkg/kubectl/resource_printer.go b/pkg/kubectl/resource_printer.go index 1628b05a725..397979f1984 100644 --- a/pkg/kubectl/resource_printer.go +++ b/pkg/kubectl/resource_printer.go @@ -1541,11 +1541,11 @@ func (p *TemplatePrinter) PrintObj(obj runtime.Object, w io.Writer) error { // It is way easier to debug this stuff when it shows up in // stdout instead of just stdin. So in addition to returning // a nice error, also print useful stuff with the writer. - fmt.Fprintf(w, "Error executing template: %v\n", err) - fmt.Fprintf(w, "template was:\n\t%v\n", p.rawTemplate) - fmt.Fprintf(w, "raw data was:\n\t%v\n", string(data)) - fmt.Fprintf(w, "object given to template engine was:\n\t%+v\n", out) - return fmt.Errorf("error executing template '%v': '%v'\n----data----\n%+v\n", p.rawTemplate, err, out) + 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", p.rawTemplate) + fmt.Fprintf(w, "\traw data was:\n\t\t%v\n", string(data)) + fmt.Fprintf(w, "\tobject given to template engine was:\n\t\t%+v\n\n", out) + return fmt.Errorf("error executing template %q: %v", p.rawTemplate, err) } return nil } @@ -1692,10 +1692,10 @@ 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\n", err) - fmt.Fprintf(w, "template was:\n\t%v\n", j.rawTemplate) - fmt.Fprintf(w, "object given to jsonpath engine was:\n\t%#v\n", queryObj) - return fmt.Errorf("error executing jsonpath '%v': '%v'\n----data----\n%+v\n", j.rawTemplate, err, obj) + 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) } return nil }