{"record":{"id":"5dc5732238d72a9e","repo":"gohugoio/hugo","slug":"failed-to-render-shortcode-q-w","errorCode":null,"errorMessage":"failed to render shortcode %q: %w","messagePattern":"failed to render shortcode %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"hugolib/shortcode.go","lineNumber":332,"sourceCode":"}\n\nconst (\n\tinnerNewlineRegexp = \"\\n\"\n\tinnerCleanupRegexp = `\\A<p>(.*)</p>\\n\\z`\n\tinnerCleanupExpand = \"$1\"\n)\n\nfunc prepareShortcode(\n\tlevel int,\n\tsc *shortcode,\n\tparent *ShortcodeWithPage,\n\tpo *pageOutput,\n\tisRenderString bool,\n) (shortcodeRenderer, error) {\n\tp := po.p\n\ttoParseErr := func(err error) error {\n\t\tsource := p.m.content.mustSource()\n\t\treturn p.parseError(fmt.Errorf(\"failed to render shortcode %q: %w\", sc.name, err), source, sc.pos)\n\t}\n\n\t// Allow the caller to delay the rendering of the shortcode if needed.\n\tvar fn shortcodeRenderFunc = func(ctx context.Context) ([]byte, bool, error) {\n\t\tif p.m.pageConfigSource.ContentMediaType.IsMarkdown() && sc.doMarkup {\n\t\t\t// Signal downwards that the content rendered will be\n\t\t\t// parsed and rendered by Goldmark.\n\t\t\tctx = tpl.Context.IsInGoldmark.Set(ctx, true)\n\t\t}\n\t\tr, err := doRenderShortcode(ctx, level, po.p.s.TemplateStore, sc, parent, po, isRenderString)\n\t\tif err != nil {\n\t\t\treturn nil, false, toParseErr(err)\n\t\t}\n\n\t\tb, hasVariants, err := r.renderShortcode(ctx)\n\t\tif err != nil {\n\t\t\treturn nil, false, toParseErr(err)\n\t\t}","sourceCodeStart":314,"sourceCodeEnd":350,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/hugolib/shortcode.go#L314-L350","documentation":"Generic wrapper emitted by prepareShortcode's toParseErr (shortcode.go:332). Any failure inside doRenderShortcode (template lookup, parse, execution) or the subsequent renderShortcode is wrapped with the shortcode name and surfaced with source position via parseError. The underlying cause is in the wrapped error chain.","triggerScenarios":"A shortcode template references an undefined function or method; passes wrong argument types; raises a runtime error (nil deref in template, division by zero); a nested shortcode errors; the shortcode template file has a Go-template syntax error.","commonSituations":"Editing a shortcode template and introducing a bug; content that exercises a previously-unreached code path in the shortcode; theme upgrade where a shortcode helper changed signature; passing unexpected param types from content.","solutions":["Read the wrapped error — it names the shortcode and the inner cause; open that template and fix the reported issue.","Reproduce with a minimal content snippet and run `hugo server` for live error context.","Add `with`/`default` guards in the shortcode template for params that may be absent or mistyped."],"exampleFix":"{{/* before (layouts/shortcodes/note.html) */}}\n{{ .Get \"type\" | upper }}\n\n{{/* after: guard against missing param */}}\n{{ with .Get \"type\" }}{{ . | upper }}{{ end }}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"{{/* Guard shortcode params to prevent runtime errors in the template */}}\n{{ $type := .Get \"type\" | default \"info\" }}\n{{ with .Get \"title\" }}{{ . }}{{ end }}","tryCatchPattern":null,"preventionTips":["Default all .Get values: `{{ .Get \"x\" | default \"...\" }}`.","Use `with` guards for optional params and nested maps.","Smoke-test shortcodes with a fixture content page in CI."],"tags":["shortcode","templates","runtime"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}