{"id":"259a8b2f316a6fdc","repo":"gohugoio/hugo","slug":"must-provide-a-resource-object","errorCode":null,"errorMessage":"must provide a Resource object","messagePattern":"must provide a Resource object","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/resources/resources.go","lineNumber":263,"sourceCode":"\ttargetPath, err := cast.ToStringE(args[0])\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tdata := args[1]\n\n\tr, ok := args[2].(resources.ResourceTransformer)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"type %T not supported in Resource transformations\", args[2])\n\t}\n\n\treturn ns.templatesClient.ExecuteAsTemplate(ctx, r, targetPath, data)\n}\n\n// Fingerprint transforms the given Resource with a MD5 hash of the content in\n// the RelPermalink and Permalink.\nfunc (ns *Namespace) Fingerprint(args ...any) (resource.Resource, error) {\n\tif len(args) < 1 {\n\t\treturn nil, errors.New(\"must provide a Resource object\")\n\t}\n\n\tif len(args) > 2 {\n\t\treturn nil, errors.New(\"must not provide more arguments than Resource and hash algorithm\")\n\t}\n\n\tvar algo string\n\tresIdx := 0\n\n\tif len(args) == 2 {\n\t\tresIdx = 1\n\t\tvar err error\n\t\talgo, err = cast.ToStringE(args[0])\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t}\n","sourceCodeStart":245,"sourceCodeEnd":281,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/tpl/resources/resources.go#L245-L281","documentation":"`resources.Fingerprint` requires at least one argument — the Resource to hash (an optional hash algorithm string like \"sha256\" may precede it). Calling it with no arguments fails this length check before any processing. A separate error covers more than two arguments.","triggerScenarios":"`{{ resources.Fingerprint }}` with nothing piped or passed; a pipeline where the upstream step returned nothing so no resource reaches Fingerprint (e.g. `resources.Get` used in a broken chain); calling `fingerprint` as a bare function instead of piping the resource into it.","commonSituations":"Refactoring an asset pipeline and dropping the piped resource; conditional blocks where the resource variable is empty; copying docs examples without the leading `$resource |`.","solutions":["Pipe the resource in: `{{ $css := $css | fingerprint }}` or `{{ $css | fingerprint \"sha256\" }}` — the pipe supplies the Resource as the last argument.","If the resource may be nil (missing asset), guard with `with` before fingerprinting.","When specifying an algorithm, put it first and the resource last: `fingerprint \"sha512\" $r` (or via pipe)."],"exampleFix":"<!-- before -->\n{{ $secure := fingerprint }}\n<!-- after -->\n{{ $secure := $js | fingerprint \"sha256\" }}","handlingStrategy":"type-guard","validationCode":"{{ with resources.Get \"style.scss\" }}{{ $css := . | toCSS }}{{ end }}","typeGuard":"{{/* `with` narrows away nil */}}{{ with $maybeResource }}{{ resources.Minify . }}{{ end }}","tryCatchPattern":"{{ with try (resources.Minify $r) }}{{ with .Err }}{{ warnf \"minify failed: %s\" . }}{{ end }}{{ end }}","preventionTips":["Wrap resources.Get results in `with` so nil (missing file) never reaches transform functions","Pass the Resource object itself, not its .RelPermalink string","Fail loudly with errorf when a required asset is missing instead of piping nil onward"],"tags":["hugo","resources","fingerprint","arguments"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}