{"record":{"id":"3b17eec62ae7505c","repo":"gohugoio/hugo","slug":"failed-to-process-shortcode-w","errorCode":null,"errorMessage":"failed to process shortcode: %w","messagePattern":"failed to process shortcode: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"hugolib/shortcode.go","lineNumber":778,"sourceCode":"\t\t}\n\n\t\t// This and other cool slice tricks: https://github.com/golang/go/wiki/SliceTricks\n\t\tsource = append(source[:j], append(newVal, source[end:]...)...)\n\t\tstart = j\n\t\tk = bytes.Index(source[start:], pre)\n\n\t}\n\n\treturn source, nil\n}\n\nfunc renderShortcodeWithPage(ctx context.Context, h *tplimpl.TemplateStore, tmpl *tplimpl.TemplInfo, data *ShortcodeWithPage) (string, error) {\n\tbuffer := bp.GetBuffer()\n\tdefer bp.PutBuffer(buffer)\n\n\terr := h.ExecuteWithContext(ctx, tmpl, buffer, data)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to process shortcode: %w\", err)\n\t}\n\treturn buffer.String(), nil\n}\n","sourceCodeStart":760,"sourceCodeEnd":782,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/hugolib/shortcode.go#L760-L782","documentation":"Hugo successfully located and invoked a shortcode template but executing it (template ExecuteWithContext at shortcode.go:776) returned an error. This is a thin wrapper; the underlying cause is appended via %w and is usually a Go template runtime error, a method call on a nil/typed value, or an error returned from a shortcode helper.","triggerScenarios":"A shortcode template that calls a method that errors (e.g. .Page.Render on a missing layout, image processing on a missing resource, partial returning an error), references an undefined method, or hits a type mismatch during execution.","commonSituations":"Shortcode calls .Get on an index/key that does not exist and then chains a method; a resource transformation fails (missing image, unsupported format); a referenced partial is missing after a theme upgrade; a template uses a function removed in the current Hugo version.","solutions":["Read the wrapped error text after 'failed to process shortcode:' — it identifies the real failure (missing partial, nil pointer, etc.).","Open the shortcode template (layouts/shortcodes/<name>.html) and locate the offending method/function call.","Add guards in the template ({{ with ... }}/{{ if ... }}) before chaining methods on optional values.","Verify referenced resources/partials exist under the current theme and Hugo version."],"exampleFix":"// before (shortcode template)\n<img src=\"{{ (.Resources.GetMatch (.Get \"img\")).RelPermalink }}\">\n\n// after\n{{ with .Resources.GetMatch (.Get \"img\") }}\n  <img src=\"{{ .RelPermalink }}\">\n{{ else }}\n  {{ errorf \"image %q not found\" (.Get \"img\") }}\n{{ end }}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Shortcodes are invoked by Hugo's render pipeline; guard inside the template.\n{{ with .Resources.GetMatch (.Get \"img\") }}\n  <img src=\"{{ .RelPermalink }}\">\n{{ else }}\n  {{ errorf \"shortcode %q: image %q not found\" .Name (.Get \"img\") }}\n{{ end }}","preventionTips":["Guard optional values in shortcode templates with {{ with }} before chaining methods.","Use {{ errorf }} to emit a clear message instead of a nil-pointer template error.","Test shortcodes against minimal content in hugo server before broad use."],"tags":["shortcode","template","rendering","hugo"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}