{"id":"b235d147062008c2","repo":"gohugoio/hugo","slug":"no-resource-provided-in-transformation","errorCode":null,"errorMessage":"no Resource provided in transformation","messagePattern":"no Resource provided in transformation","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/internal/resourcehelpers/helpers.go","lineNumber":44,"sourceCode":"// We allow string or a map as the first argument in some cases.\nfunc ResolveIfFirstArgIsString(args []any) (resources.ResourceTransformer, string, bool) {\n\tif len(args) != 2 {\n\t\treturn nil, \"\", false\n\t}\n\n\tv1, ok1 := args[0].(string)\n\tif !ok1 {\n\t\treturn nil, \"\", false\n\t}\n\tv2, ok2 := args[1].(resources.ResourceTransformer)\n\n\treturn v2, v1, ok2\n}\n\n// This roundabout way of doing it is needed to get both pipeline behavior and options as arguments.\nfunc ResolveArgs(args []any) (resources.ResourceTransformer, map[string]any, error) {\n\tif len(args) == 0 {\n\t\treturn nil, nil, errors.New(\"no Resource provided in transformation\")\n\t}\n\n\tif len(args) == 1 {\n\t\tr, ok := args[0].(resources.ResourceTransformer)\n\t\tif !ok {\n\t\t\treturn nil, nil, fmt.Errorf(\"type %T not supported in Resource transformations\", args[0])\n\t\t}\n\t\treturn r, nil, nil\n\t}\n\n\tr, ok := args[1].(resources.ResourceTransformer)\n\tif !ok {\n\t\tif _, ok := args[1].(map[string]any); !ok {\n\t\t\treturn nil, nil, fmt.Errorf(\"no Resource provided in transformation\")\n\t\t}\n\t\treturn nil, nil, fmt.Errorf(\"type %T not supported in Resource transformations\", args[0])\n\t}\n","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/tpl/internal/resourcehelpers/helpers.go#L26-L62","documentation":"ResolveArgs backs Hugo's resource-transformation template functions (resources.Minify, resources.Fingerprint, resources.PostCSS, resources.Babel, etc.), which accept `(resource)` or `(options, resource)` to support both call and pipeline styles. With zero args there is no resource to transform, so Hugo errors immediately. The same message is also reused at line 58 when two args are given but the second is neither a ResourceTransformer nor an options map.","triggerScenarios":"Calling a transform with no arguments: `{{ resources.Minify }}`, or a broken pipeline where the piped resource evaluates to nothing; two-arg calls where the second argument is not a resource or map.","commonSituations":"`resources.Get` returned nil (missing asset file) and the nil was piped into Minify/Fingerprint; partial refactors that dropped the resource argument; wrong pipe order putting options last.","solutions":["Ensure the resource exists and is passed: `{{ $css := resources.Get \"css/main.css\" }}{{ with $css }}{{ .| minify }}{{ end }}`.","Guard against nil from resources.Get with `with` or an explicit errorf.","In pipelines, options come first: `$r | resources.PostCSS $opts` is `PostCSS $opts $r`."],"exampleFix":"<!-- before -->\n{{ $css := resources.Get \"css/mian.css\" | minify }}\n<!-- after -->\n{{ $css := resources.Get \"css/main.css\" }}\n{{ with $css }}{{ $min := . | minify }}{{ end }}","handlingStrategy":"validation","validationCode":"{{ $img := resources.Get \"logo.png\" }}\n{{ if $img }}{{ $small := $img.Resize \"200x\" }}{{ else }}{{ warnf \"logo.png not found\" }}{{ end }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always nil-check the result of resources.Get / .Resources.Get before piping into a transformation","Pass the resource explicitly as the last argument when using function-style calls (e.g. images.Filter)","Fail loudly with errorf for required assets instead of silently skipping"],"tags":["hugo","templates","hugo-pipes","resources","asset-pipeline"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}