{"record":{"id":"aa2d82eb4cb91900","repo":"gohugoio/hugo","slug":"resource-d-to-post-process-is-nil","errorCode":null,"errorMessage":"resource %d to post process is nil","messagePattern":"resource (.+?) to post process is nil","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"hugolib/hugo_sites_build.go","lineNumber":732,"sourceCode":"\t\tk := 0\n\t\tchanged := false\n\n\t\tfor {\n\t\t\tl := bytes.Index(content[k:], []byte(postpub.PostProcessPrefix))\n\t\t\tif l == -1 {\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tm := bytes.Index(content[k+l:], []byte(postpub.PostProcessSuffix)) + len(postpub.PostProcessSuffix)\n\n\t\t\tlow, high := k+l, k+l+m\n\n\t\t\tfield := content[low:high]\n\n\t\t\tforward := l + m\n\n\t\t\tfor i, r := range toPostProcess {\n\t\t\t\tif r == nil {\n\t\t\t\t\tpanic(fmt.Sprintf(\"resource %d to post process is nil\", i+1))\n\t\t\t\t}\n\t\t\t\tv, ok := r.GetFieldString(string(field))\n\t\t\t\tif ok {\n\t\t\t\t\tcontent = append(content[:low], append([]byte(v), content[high:]...)...)\n\t\t\t\t\tchanged = true\n\t\t\t\t\tforward = len(v)\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tk += forward\n\t\t}\n\n\t\tif changed {\n\t\t\treturn afero.WriteFile(h.BaseFs.PublishFs, filename, content, 0o666)\n\t\t}\n\n\t\treturn nil","sourceCodeStart":714,"sourceCodeEnd":750,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/hugolib/hugo_sites_build.go#L714-L750","documentation":"Panic during post-publish resource substitution: iterating over the collected toPostProcess resources, an entry r is nil. Post-process resources are those marked with a post-publish placeholder (e.g. | SAFEHTMLURL or css.Suffix style references resolved after publish); a nil entry means the PostProcessResources map was populated with a nil value. This is an internal invariant failure.","triggerScenarios":"A template/resource marks a resource for post-processing but the resource object becomes nil before the publish substitution pass (e.g. a resource lookup returned nil and was still registered). Concurrent mutation of the PostProcessResources concurrent map. A custom output/resource type that does not satisfy the expected interface.","commonSituations":"Using resource post-publish features (e.g. minify/css/js pipe with post-process placeholders) where a referenced resource is missing or failed to create. Incremental build staleness after deleting a resource. Hugo version mismatch.","solutions":["Clean the build (remove public/, resources/_gen, build lock) and rebuild from scratch.","Audit templates that use post-process resource placeholders for a resource that could be nil (guard with 'with' / 'if').","Upgrade Hugo to the current release; report if it reproduces with a minimal project."],"exampleFix":"{{/* before: resource may be nil but is registered for post-process */}}\n{{ $css := resources.Get \"main.css\" | minify | fingerprint }}\n<link rel=\"stylesheet\" href=\"{{ $css.Permalink }}\">\n\n{{/* after: guard so nil is never registered */}}\n{{ with resources.Get \"main.css\" }}\n  {{ $css := . | minify | fingerprint }}\n  <link rel=\"stylesheet\" href=\"{{ $css.Permalink }}\">\n{{ end }}","handlingStrategy":"validation","validationCode":"// In templates, guard resource lookups so nil is never registered for post-processing:\n//   {{ with resources.Get \"main.css\" }}{{ $css := . | minify }}<link href=\"{{ $css.Permalink }}\">{{ end }}\n// Programmatically, ensure any resource registered in PostProcessResources is non-nil.","typeGuard":null,"tryCatchPattern":"// Wrap the build in a recover() to convert the panic to an error (see 781).","preventionTips":["Use Hugo's 'with'/'if' guards around resource lookups.","Clean-rebuild when post-process panics appear.","Verify referenced assets exist before pipelining them.","Keep Hugo current."],"tags":["resources","post-publish","build","panic","internal-invariant"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}