From f70435a20fb9641513aff9c94ea368973c39d252 Mon Sep 17 00:00:00 2001 From: Elwardi Date: Mon, 19 Jul 2021 13:31:44 +0100 Subject: [PATCH] Better format error catching in menuFromCommand prompts --- pkg/gui/custom_commands.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pkg/gui/custom_commands.go b/pkg/gui/custom_commands.go index 1ac92f49c..c258b600f 100644 --- a/pkg/gui/custom_commands.go +++ b/pkg/gui/custom_commands.go @@ -185,7 +185,10 @@ func (gui *Gui) handleCustomCommandKeybinding(customCommand config.CustomCommand // Need to make a menu out of what the cmd has displayed candidates := []string{} buff := bytes.NewBuffer(nil) - temp := template.Must(template.New("format").Parse(prompt.Format)) + temp, err := template.New("format").Parse(prompt.Format) + if err != nil { + return gui.surfaceError(errors.New("unable to parse format, error: " + err.Error())) + } for _, str := range strings.Split(string(message), "\n") { if str == "" { continue @@ -203,7 +206,11 @@ func (gui *Gui) handleCustomCommandKeybinding(customCommand config.CustomCommand } } } - temp.Execute(buff, tmplData) + err = temp.Execute(buff, tmplData) + if err != nil { + return gui.surfaceError(err) + } + candidates = append(candidates, strings.TrimSpace(buff.String())) buff.Reset() }