{"record":{"id":"b9381a041ea114ca","repo":"gohugoio/hugo","slug":"failed-to-render-shortcode-w","errorCode":null,"errorMessage":"failed to render shortcode: %w","messagePattern":"failed to render shortcode: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"hugolib/page__content.go","lineNumber":249,"sourceCode":"\t\tcase pageparser.Item:\n\t\t\tsm = append(sm, sourceMapEntry{renderOffset: len(c), sourceOffset: v.Pos()})\n\t\t\tc = append(c, source[v.Pos():v.Pos()+len(v.Val(source))]...)\n\t\tcase pageContentReplacement:\n\t\t\tsm = append(sm, sourceMapEntry{renderOffset: len(c), sourceOffset: v.source.Pos()})\n\t\t\tc = append(c, v.val...)\n\t\tcase *shortcode:\n\t\t\tsm = append(sm, sourceMapEntry{renderOffset: len(c), sourceOffset: v.pos, isShortcode: true})\n\t\t\tif !v.insertPlaceholder() {\n\t\t\t\t// Insert the rendered shortcode.\n\t\t\t\trenderedShortcode, found := renderedShortcodes[v.placeholder]\n\t\t\t\tif !found {\n\t\t\t\t\t// This should never happen.\n\t\t\t\t\tpanic(fmt.Sprintf(\"rendered shortcode %q not found\", v.placeholder))\n\t\t\t\t}\n\n\t\t\t\tb, more, err := renderedShortcode.renderShortcode(ctx)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn nil, nil, false, fmt.Errorf(\"failed to render shortcode: %w\", err)\n\t\t\t\t}\n\t\t\t\thasVariants = hasVariants || more\n\t\t\t\tc = append(c, []byte(b)...)\n\n\t\t\t} else {\n\t\t\t\t// Insert the placeholder so we can insert the content after\n\t\t\t\t// markdown processing.\n\t\t\t\tc = append(c, []byte(v.placeholder)...)\n\t\t\t}\n\t\tdefault:\n\t\t\tpanic(fmt.Sprintf(\"unknown item type %T\", it))\n\t\t}\n\t}\n\n\treturn c, sm, hasVariants, nil\n}\n\nfunc (c *cachedContent) IsZero() bool {","sourceCodeStart":231,"sourceCodeEnd":267,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/hugolib/page__content.go#L231-L267","documentation":"Emitted during the second content-assembly pass (page__content.go:249) when rendering an already-parsed shortcode into HTML fails. The %w carries the concrete shortcode-render error (template execution failure, nested-shortcode error, or a function-call error inside the shortcode template).","triggerScenarios":"A shortcode template executes an undefined function, references a missing partial, divides by zero, calls a method that errors, or nests a shortcode whose own render fails. The failure happens while expanding the renderedShortcode into the page's content byte stream.","commonSituations":"Typo in a shortcode parameter/function name; a shortcode partial deleted but still referenced; a shortcode that worked in one Hugo version but uses a changed/removed API; data fed to a shortcode that violates an assertion.","solutions":["Use the wrapped %w to get the template/function name and line that failed.","Open the named shortcode template (layouts/shortcodes/*.html) and fix the reported call.","Verify any partial the shortcode includes exists and renders standalone.","Check the parameters passed in the page content match what the shortcode expects."],"exampleFix":"// before\n{{< myshortcode badparam >}}\n\n// after: correct the parameter the shortcode template errors on\n{{< myshortcode param=\"value\" >}}","handlingStrategy":"try-catch","validationCode":"# lint shortcode references resolve before building\ngrep -rhoE '\\{\\{<[^>]+>\\}\\}' content/ | sort -u   # then check each name exists under layouts/shortcodes/","typeGuard":null,"tryCatchPattern":"{{ with try (templates.Execute (dict)) }}{{ . }}{{ else }}{{ errorf \"shortcode failed: %s\" . }}{{ end }}","preventionTips":["Keep shortcode templates self-contained; verify partials they include exist.","Validate shortcode parameter names match the template.","Use `errorf` in shortcode templates to fail loudly with context instead of panicking."],"tags":["shortcode","render","templates","content"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}