From 505244bea22362b6e8899399e5699dd470cf3f93 Mon Sep 17 00:00:00 2001 From: Edd Salkield Date: Tue, 4 Oct 2022 15:22:51 +0100 Subject: [PATCH] page.go: report error in template override failure Raise an error when users specify a template in frontmatter which cannot be resolved. --- page.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/page.go b/page.go index b62fddc..5679bbd 100644 --- a/page.go +++ b/page.go @@ -199,6 +199,9 @@ func (p *Page) process(cfg *Site, task *Task) error { tmplName = "index" } tmpl, ok := cfg.templates.FindTemplate(p.FilePath, tmplName+task.TemplateExt) + if !ok && p.Template != "" { + return fmt.Errorf("failed to generate index page %q: template %q specified in frontmatter but not found", p.Path, tmplName) + } if ok { var b strings.Builder if err := tmpl.Execute(&b, p); err != nil { @@ -216,6 +219,9 @@ func (p *Page) process(cfg *Site, task *Task) error { } var b strings.Builder tmpl, ok := cfg.templates.FindTemplate(p.FilePath, tmplName+task.TemplateExt) + if !ok && p.Pages[i].Template != "" { + return fmt.Errorf("failed to generate page %q: template %q specified in frontmatter but not found", p.Pages[i].Path, tmplName) + } if ok { if err := tmpl.Execute(&b, p.Pages[i]); err != nil { return err