{"id":"c4feffaa6cf1cd24","repo":"gohugoio/hugo","slug":"failed-to-create-resource-for-path-q-expected-a","errorCode":null,"errorMessage":"failed to create resource for path %q, expected a resource.Resource, got %T","messagePattern":"failed to create resource for path %q, expected a resource\\.Resource, got %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"resources/resource_spec.go","lineNumber":169,"sourceCode":"\tFileCaches    filecache.Caches\n\n\t// Assets used after the build is done.\n\t// This is shared between all sites.\n\t*PostBuildAssets\n}\n\ntype PostBuildAssets struct {\n\tPostProcessResources *maphelpers.ConcurrentMap[string, postpub.PostPublishedResource]\n\tJSConfigBuilder      *jsconfig.Builder\n}\n\nfunc (r *Spec) NewResourceWrapperFromResourceConfig(rc *pagemeta.ResourceConfig) (resource.Resource, error) {\n\tcontent := rc.Content\n\tswitch r := content.Value.(type) {\n\tcase resource.Resource:\n\t\treturn cloneWithMetadataFromResourceConfigIfNeeded(rc, r), nil\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"failed to create resource for path %q, expected a resource.Resource, got %T\", rc.PathInfo.Path(), content.Value)\n\t}\n}\n\n// NewResource creates a new Resource from the given ResourceSourceDescriptor.\nfunc (r *Spec) NewResource(rd ResourceSourceDescriptor) (resource.Resource, error) {\n\tif err := rd.init(r); err != nil {\n\t\treturn nil, err\n\t}\n\n\tdir, name := path.Split(rd.TargetPath)\n\tdir = paths.ToSlashPreserveLeading(dir)\n\tif dir == \"/\" {\n\t\tdir = \"\"\n\t}\n\trp := internal.ResourcePaths{\n\t\tFile:            name,\n\t\tDir:             dir,\n\t\tBaseDirTarget:   rd.BasePathTargetPath,","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/resources/resource_spec.go#L151-L187","documentation":"`Spec.NewResourceWrapperFromResourceConfig` in resources/resource_spec.go wraps an already-existing resource declared in front matter. It type-switches on `rc.Content.Value` and only accepts a `resource.Resource`; anything else means the front matter asked Hugo to wrap something that isn't a resource, and it reports the path plus the actual Go type. This path is distinct from creating a resource from literal content — that goes through `NewResource`.","triggerScenarios":"A page-resource entry in front matter whose `content.value` is a plain string, map, or number where a resource object was required by the code path (resource wrapping rather than resource creation); or template/module code building a `pagemeta.ResourceConfig` and passing a non-Resource value into `Content.Value` before calling `NewResourceWrapperFromResourceConfig`.","commonSituations":"Programmatically constructing page resources from a data file or template and forgetting to resolve the value through `resources.Get`/`.Resources.Get` first, so a path string is passed instead of the Resource; mixing the two front matter styles (inline literal content vs. referencing an existing resource) in one entry.","solutions":["Resolve the value to an actual resource first (e.g. `resources.Get` or `.Resources.GetMatch`) and assign that object to `content.value`.","If you intended literal inline content rather than wrapping an existing resource, use the inline-content form with `content.mediaType` + string `value` so Hugo takes the create path instead of the wrap path.","Check the `%T` in the message — `string` almost always means a path was passed where the resolved Resource was expected.","Guard against nil: a failed `resources.Get` returns nil, which will also land here, so check the lookup succeeded before assigning."],"exampleFix":"{{/* before */}}\n{{ $rc := dict \"path\" \"images/hero.jpg\" \"content\" (dict \"value\" \"images/hero.jpg\") }}\n\n{{/* after */}}\n{{ $r := resources.Get \"images/hero.jpg\" }}\n{{ with $r }}\n  {{ $rc := dict \"path\" \"images/hero.jpg\" \"content\" (dict \"value\" .) }}\n{{ end }}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"// when implementing custom resource factories, guarantee a resource.Resource\nfunc asResource(v any) (resource.Resource, bool) {\n    r, ok := v.(resource.Resource)\n    return r, ok\n}","tryCatchPattern":null,"preventionTips":["Ensure paths passed to resources.Get/GetMatch point to real files under assets/","Don't pass directories or empty paths where a file resource is expected","If extending Hugo, make factory functions return a concrete type satisfying resource.Resource"],"tags":["hugo","page-resources","resource-spec","type-error","front-matter"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}