From 6f04353512a4c706435f3e72794a06f890b4890d Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Sun, 8 Dec 2024 01:00:50 -0500 Subject: [PATCH] providers/import: Add panic function --- providers/import/import.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/providers/import/import.go b/providers/import/import.go index 013809b..a7f1a5b 100644 --- a/providers/import/import.go +++ b/providers/import/import.go @@ -1,5 +1,7 @@ package impor +import "fmt" +import "errors" import "strings" import "html/template" import "git.tebibyte.media/sashakoshka/step" @@ -22,6 +24,7 @@ func (this *Provider) FuncMapFor (document *step.Document) template.FuncMap { document: document, } return template.FuncMap { + "panic": stat.funcPanic, "execute": stat.funcExecute, "include": stat.funcInclude, "includeHTML": stat.funcIncludeHTML, @@ -32,6 +35,14 @@ type state struct { document *step.Document } +func (this *state) funcPanic (message any) (string, error) { + if err, ok := message.(error); ok { + return "", err + } else { + return "", errors.New(fmt.Sprint(message)) + } +} + func (this *state) funcExecute (name string, data any) (step.ExecutionResult, error) { document, err := this.document.Environment().Parse(name) if err != nil { return step.ExecutionResult { }, err }