From af763240f03d2f9f91c3bb3cce15d320acfd6223 Mon Sep 17 00:00:00 2001 From: early Date: Tue, 22 Oct 2024 23:01:04 -0600 Subject: [PATCH] No more panics! --- page/page.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/page/page.go b/page/page.go index d3ea5e9..95879e7 100644 --- a/page/page.go +++ b/page/page.go @@ -26,6 +26,8 @@ type Page struct { template *template.Template templateFuncs template.FuncMap templateLoad render.Loader + + err error } type Config func(*Page) @@ -89,7 +91,8 @@ func New(name string, source string, optional ...func(*Page)) *Page { } result, err := compile.Compile(p, sourceTransform) if err != nil { - panic(err) + p.err = err + return p } p.raw = result.TemplateRaw p.templateLoad = result.TemplateDataLoader @@ -99,7 +102,8 @@ func New(name string, source string, optional ...func(*Page)) *Page { Funcs(result.TemplateFuncs). Parse(result.TemplateRaw) if err != nil { - panic(err) + p.err = err + return p } return p } @@ -175,3 +179,7 @@ func (p *Page) Includes() []compile.Source { func (p *Page) Raw() string { return p.raw } + +func (p *Page) Error() error { + return p.err +} -- 2.39.5