{"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/8a468df065a75c1c7cf9f6850f32148746590ea5/hugolib/shortcode.go#L760-L782","documentation":"Raised in renderShortcodeWithPage (hugolib/shortcode.go:778) when executing a shortcode template via the template store fails. Hugo wraps the underlying template execution error so the user sees which stage failed; the real cause is inside the wrapped error — a template syntax/runtime error, a nil or missing value, or a failing function call inside the shortcode template.","triggerScenarios":"Any page containing {{< myshortcode >}} or {{% myshortcode %}} whose template (layouts/_shortcodes/myshortcode.html or an embedded shortcode) errors during ExecuteWithContext — e.g. calling a method on nil, .Get with a missing param used unsafely, errorf/resources.GetRemote failures, or a Go template runtime error.","commonSituations":"Custom shortcodes broken after a Hugo upgrade (deprecated methods removed), shortcodes assuming a named parameter that a page omits, resources/images referenced by the shortcode not existing, or partials called from the shortcode failing. Often surfaces only for the one page passing bad arguments.","solutions":["Read the wrapped error after the colon — it names the template file, line, and the actual failure.","Fix the shortcode template: guard optional params (e.g. {{ with .Get \"param\" }}) and nil resources before use.","Check the calling page's shortcode invocation for missing/misspelled parameters.","If it appeared after upgrading Hugo, check the release notes for removed template methods used by the shortcode."],"exampleFix":"// before (layouts/_shortcodes/img.html)\n{{ $img := resources.Get (.Get \"src\") }}\n<img src=\"{{ $img.RelPermalink }}\">\n// after\n{{ with resources.Get (.Get \"src\") }}\n<img src=\"{{ .RelPermalink }}\">\n{{ else }}\n{{ errorf \"img shortcode: resource %q not found in %s\" (.Get \"src\") .Page.Path }}\n{{ end }}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"err := hugolib.Build(...)\nif err != nil {\n    // wrapped chain: \"failed to process shortcode: ...\" carries position info\n    var fe herrors.FileError\n    if errors.As(err, &fe) {\n        log.Printf(\"shortcode error at %s: %v\", fe.Position(), fe)\n    }\n    return err\n}","preventionTips":["Validate shortcode templates and their parameters in a CI build before deploying content","Keep shortcode names in content matched to files under layouts/_shortcodes/","Run `hugo --panicOnWarning` or a dry build in CI so bad shortcode invocations fail early","Use errors.As with herrors.FileError to surface file:line positions to authors"],"tags":["hugo","shortcode","template","go-template"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}