diff options
author | Daniel J Walsh <dwalsh@redhat.com> | 2020-07-29 14:10:59 -0400 |
---|---|---|
committer | Matthew Heon <matthew.heon@pm.me> | 2020-07-31 11:42:40 -0400 |
commit | 9b1a7894a1aa3097c7f7901e9087f04ca04788e1 (patch) | |
tree | 0e55dbeecc74c38a8eb4636f418bfe51c899f259 | |
parent | da752a7ed32f90a3f187eeb5f3f372889561a021 (diff) | |
download | podman-9b1a7894a1aa3097c7f7901e9087f04ca04788e1.tar.gz podman-9b1a7894a1aa3097c7f7901e9087f04ca04788e1.tar.bz2 podman-9b1a7894a1aa3097c7f7901e9087f04ca04788e1.zip |
Don't crash when giving bogus format commands
Currently if you give a bogus flag to --format it will crash
the formatter. With this change we will get a nice error.
podman images --format '{{ bogus }}'
Error: template: list:1: function "bogus" not defined
versus
/bin/podman.old images --format '{{ bogus }}'
panic: template: list:1: function "bogus" not defined
goroutine 1 [running]:
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
<MH: Fixed compile after cherry pick>
Signed-off-by: Matthew Heon <matthew.heon@pm.me>
-rw-r--r-- | cmd/podman/images/history.go | 5 | ||||
-rw-r--r-- | cmd/podman/images/list.go | 6 |
2 files changed, 9 insertions, 2 deletions
diff --git a/cmd/podman/images/history.go b/cmd/podman/images/history.go index 3732e6e03..1f0fd9a79 100644 --- a/cmd/podman/images/history.go +++ b/cmd/podman/images/history.go @@ -125,7 +125,10 @@ func history(cmd *cobra.Command, args []string) error { } format := hdr + "{{range . }}" + row + "{{end}}" - tmpl := template.Must(template.New("report").Parse(format)) + tmpl, err := template.New("report").Parse(format) + if err != nil { + return err + } w := tabwriter.NewWriter(os.Stdout, 8, 2, 2, ' ', 0) err = tmpl.Execute(w, hr) if err != nil { diff --git a/cmd/podman/images/list.go b/cmd/podman/images/list.go index 94d03bd6f..ea88b519b 100644 --- a/cmd/podman/images/list.go +++ b/cmd/podman/images/list.go @@ -168,7 +168,11 @@ func writeTemplate(imgs []imageReporter) error { } } format := hdr + "{{range . }}" + row + "{{end}}" - tmpl := template.Must(template.New("list").Parse(format)) + tmpl, err := template.New("list").Parse(format) + if err != nil { + return err + } + tmpl = template.Must(tmpl, nil) w := tabwriter.NewWriter(os.Stdout, 8, 2, 2, ' ', 0) defer w.Flush() return tmpl.Execute(w, imgs) |