From 9917fc0f956c849ec2d52f3f873aa6eaa3f25e72 Mon Sep 17 00:00:00 2001 From: Daniel J Walsh Date: Wed, 29 Jul 2020 14:10:59 -0400 Subject: 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 --- cmd/podman/system/connection/list.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'cmd/podman/system') diff --git a/cmd/podman/system/connection/list.go b/cmd/podman/system/connection/list.go index 6d3d85d11..9010ec803 100644 --- a/cmd/podman/system/connection/list.go +++ b/cmd/podman/system/connection/list.go @@ -75,7 +75,11 @@ func list(_ *cobra.Command, _ []string) error { // TODO: Allow user to override format format := "{{range . }}{{.Name}}\t{{.Identity}}\t{{.URI}}\n{{end}}" - tmpl := template.Must(template.New("connection").Parse(format)) + tmpl, err := template.New("connection").Parse(format) + if err != nil { + return err + } + w := tabwriter.NewWriter(os.Stdout, 8, 2, 2, ' ', 0) defer w.Flush() -- cgit v1.2.3-54-g00ecf