{"record":{"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/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/internal/resourcehelpers/helpers.go#L26-L62","documentation":"Thrown by resourcehelpers.ResolveArgs (tpl/internal/resourcehelpers/helpers.go:44) when a resource transformation function (e.g. js.Build, css.Sass, toCSS, minify) is called with zero arguments. Resource-transforming template functions expect the resource to transform as a piped or positional argument; with no args there is nothing to transform.","triggerScenarios":"Calling {{ js.Build }} with nothing piped in, or {{ (resources.Get \"main.js\").WrongMethod }} where the pipeline produces nil and is then passed; forgetting the pipe: {{ js.Build \"opts\" }} where the resource was intended but omitted.","commonSituations":"Refactoring a pipeline and accidentally dropping the resource; resources.Get returning nil because the path was wrong, then piping nil into js.Build; misreading docs and calling the function with only an options map.","solutions":["Pipe the resource in: {{ $js := resources.Get \"js/main.js\" | js.Build }}.","Check the resource is non-nil before transforming: {{ with resources.Get \"js/main.js\" }}{{ js.Build . }}{{ end }}.","Verify the asset path exists under assets/ (resources.Get only looks in the asset filesystem).","If using positional args, pass the resource first: {{ js.Build $resource (dict \"targetPath\" \"main.js\") }}."],"exampleFix":"// before\n{{ $bundled := js.Build (dict \"targetPath\" \"app.js\") }}\n\n// after\n{{ $r := resources.Get \"js/app.js\" }}\n{{ $bundled := js.Build $r (dict \"targetPath\" \"app.js\") }}","handlingStrategy":"validation","validationCode":"// Confirm the resource exists before transforming:\n{{ with resources.Get \"js/main.js\" }}\n  {{ $out := js.Build . }}\n{{ end }}","typeGuard":"// Go caller of resourcehelpers.ResolveArgs:\nfunc isResourceTransformer(v any) bool {\n    _, ok := v.(resources.ResourceTransformer)\n    return ok\n}","tryCatchPattern":null,"preventionTips":["Always pipe a resource into transformation functions.","Use {{ with resources.Get ... }} to handle a possibly-missing asset.","Verify the asset path is correct and the file lives under assets/.","Pass the resource as the first positional arg, not only an options map."],"tags":["hugo","template","resource","pipeline","argument-validation"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}