Backtestshugorun-20260930-140149#15052

Issue #15052 Merged fix PR # Run 30 Sep 2026 · run-20260930-140149 gohugoio/hugo

hugolib: Throw error when Render method is unable to find specified template

Worse

The merged fix was judged better than our patch.

In this judgment, Patch A = our agent, Patch B = the merged fix.

The two patches are nearly identical. Both replace the silent `return "", nil` in `pageContentOutput.Render` with an error naming the missing layout, which fixes the root cause. Both add essentially the issue's integration test, and both carry the same small fix to the malformed txtar header in `tpl/page/page_integration_test.go`. The only substantive difference is error construction. Patch A wraps the error with `pco.po.p.wrapError(...)`, which attaches the page's content-file context. The error is really a template/layout problem, and it already surfaces through template execution. Go's text/template reports it as an 'error calling Render' at the calling template's file, line and column. So the page wrapping is at best redundant. At worst it could point the reported error location at the content file rather than the template that made the bad call. Patch B returns a plain `fmt.Errorf`, which lets the template engine supply accurate location context and matches how other template-function errors propagate. On tests, B's `qt.ErrorMatches` on `template "view_bar" not found` is slightly more precise than A's `IsNotNil` plus a check that the message contains `"view_bar"`. Both tests would fail before the change and pass after it. Scope is equivalent. The difference is small, but B is the cleaner, lower-risk fix.

The judge saw only the two patches, labelled A and B in random order, with issue links and version numbers removed. The reasoning above is shown verbatim.

Solve

25m 33s17 turns

Wall-clock time in the container

Full test suite

No new failures

3,661 passed · 92 skipped · 3,762 total

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

22vs 21 merged

Changed lines, ours vs merged

Currently, when you invoke .Page.Render and pass it the name of a non-existent template, the method returns an empty string without warning or error. This isn't anything new; Hugo has behaved this way since 0.54.0, and probably earlier.

There may be a good reason for the existing behavior, but it was surprising to me.

Relevant code:

https://github.com/gohugoio/hugo/blob/d15baf53a91372843c45eef7eb5b87c25a4b6bf1/hugolib/page__per_output.go#L107-L126

Integration test:

// See issue 15052.
func TestRenderViewNotFound(t *testing.T) {
	t.Parallel()

	files := `
-- hugo.toml --
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
-- layouts/home.html --
{{ .Render "view_foo" }}
{{ .Render "view_bar" }}
-- layouts/view_foo.html --
foo
`

	b, err := hugolib.TestE(t, files)
	b.Assert(err, qt.IsNotNil) // fails (no error is thrown)
}

Reference: <https://discourse.gohugo.io/t/silent-error-with-render-function-in-v0-163-2-extended-withdeploy/57290/7>

The two patches

Our patch+21 −1
hugolib/hugo_sites_build_errors_test.goindex 3209f664d..83092e2cb 100644@@ -373,6 +373,25 @@ line 4 	b.Assert(errors[3].ErrorContext().Lines, qt.DeepEquals, []string{"line 1", "line 2", "123{{ .ThisDoesNotExist }}", "line 4"}) } +// See issue 15052.+func TestRenderViewNotFound(t *testing.T) {+	t.Parallel()++	files := `+-- hugo.toml --+disableKinds = ['page','rss','section','sitemap','taxonomy','term']+-- layouts/home.html --+{{ .Render "view_foo" }}+{{ .Render "view_bar" }}+-- layouts/view_foo.html --+foo+`++	b, err := TestE(t, files)+	b.Assert(err, qt.IsNotNil)+	b.Assert(err.Error(), qt.Contains, `"view_bar"`)+}+ func TestErrorNestedShortcode(t *testing.T) { 	t.Parallel() hugolib/page__per_output.goindex 9009165ff..ddc329348 100644@@ -114,7 +114,7 @@ func (pco *pageContentOutput) Render(ctx context.Context, layout ...string) (tem 	}  	if !found {-		return "", nil+		return "", pco.po.p.wrapError(fmt.Errorf("template %q not found", layout[0])) 	}  	// Make sure to send the *pageState and not the *pageContentOutput to the template.tpl/page/page_integration_test.goindex 817033b40..da18f553e 100644@@ -77,7 +77,7 @@ Image OK. {{ if page.IsHome }} Link OK. {{ end }}+-- layouts/myview.html -- {{ if page.IsHome }} Render OK. {{ end }} 
Merged fix · PR #+20 −1
hugolib/page__per_output.goindex 9009165ff..e8dd38ce7 100644@@ -114,7 +114,7 @@ func (pco *pageContentOutput) Render(ctx context.Context, layout ...string) (tem 	}  	if !found {-		return "", nil+		return "", fmt.Errorf("template %q not found", layout[0]) 	}  	// Make sure to send the *pageState and not the *pageContentOutput to the template.hugolib/page_test.goindex f6225cac5..803dddc01 100644@@ -2055,3 +2055,21 @@ disableKinds = ["taxonomy", "term"] 		} 	} }++// See issue 15052.+func TestRenderViewNotFound(t *testing.T) {+	t.Parallel()++	files := `+-- hugo.toml --+disableKinds = ['page','rss','section','sitemap','taxonomy','term']+-- layouts/home.html --+{{ .Render "view_foo" }}+{{ .Render "view_bar" }}+-- layouts/view_foo.html --+foo+`++	b, err := TestE(t, files)+	b.Assert(err, qt.ErrorMatches, `.*template "view_bar" not found.*`)+}tpl/page/page_integration_test.goindex 817033b40..da18f553e 100644@@ -77,7 +77,7 @@ Image OK. {{ if page.IsHome }} Link OK. {{ end }}+-- layouts/myview.html -- {{ if page.IsHome }} Render OK. {{ end }} 

What the agent reported

I've made .Render return an error when it can't find the named template, but none of it has been compiled or tested. Each ./bt-test run failed at [setup failed] because Go couldn't download the module dependencies (DNS lookup failed and proxy.golang.org returned Forbidden). No test ran, including the new one.

What was wrong: In pageContentOutput.Render (hugolib/page__per_output.go:116), when no template matched the requested layout, the code returned "", nil, so a misspelled or missing view rendered as an empty string with no error.

What I changed:

  1. The fix (hugolib/page__per_output.go:116-118): that path now returns template "view_bar" not found, wrapped with the page's path like the other errors in that function. Only the first layout name is used, because that is the only one the lookup reads.
  2. New test (hugolib/hugo_sites_build_errors_test.go): TestRenderViewNotFound is the test from the report. It checks that the build fails and that the error names "view_bar". By reading the code it should fail before the fix and pass after, but I haven't seen it do either.
  3. Existing test fixed (tpl/page/page_integration_test.go:80): one file header read -- layouts/myview.html, missing its closing --. So myview.html was never created, and its text was added to the end of render-link.html. The test's Render OK. check only passed because that text came from the link render hook while .Render "myview" returned "". With the fix, this test would fail, so I corrected the header. No assertion was removed or loosened; Render OK. now actually comes from .Render. It's the one existing test I changed.

Other code affected: Any site that relied on a missing view rendering as nothing will now fail to build, which is the point of the fix and probably worth a release note. In this repo, the only .Render "<name>" calls in tests are the two above and the new test; the one in TestErrorNestedRender points to a template that exists. No built-in templates or testscripts call .Render, and the call with no argument already returned an error. The reviewer checked all of this by reading the code and found no blocking issues.

Test evidence: None. I ran ./bt-test ./hugolib/ ./tpl/page/ -run 'TestRenderViewNotFound|TestErrorNestedRender|TestThatPageIsAvailableEverywhere' twice, and both times it exited 1 at setup. gofmt reports nothing. On a machine with network access, run that same command to confirm.

Requirements:

  • Throw an error when .Render can't find the named template: done in hugolib/page__per_output.go; not yet compiled or tested.
  • The report's test (view_foo exists, view_bar doesn't, expect an error): added exactly as TestRenderViewNotFound, but I haven't seen it fail before the fix or pass after.
  • "There may be a good reason for the existing behavior": I found none. Only the broken header in tpl/page/page_integration_test.go depended on the silent empty result.

Everything is left as uncommitted changes. The AGENTS.md and CLAUDE.md deletions were already there and I left them alone.