{"record":{"id":"9fe5200689ebf8cd","repo":"gohugoio/hugo","slug":"cannot-transform-content-of-resource-of-type-t","errorCode":null,"errorMessage":"cannot transform content of Resource of type %T","messagePattern":"cannot transform content of Resource of type %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"resources/transform.go","lineNumber":837,"sourceCode":"\n// We will persist this information to disk.\ntype transformedResourceMetadata struct {\n\tTarget     string         `json:\"Target\"`\n\tMediaTypeV string         `json:\"MediaType\"`\n\tMetaData   map[string]any `json:\"Data\"`\n}\n\n// contentReadSeekerCloser returns a ReadSeekerCloser if possible for a given Resource.\nfunc contentReadSeekerCloser(r resource.Resource) (hugio.ReadSeekCloser, error) {\n\tswitch rr := r.(type) {\n\tcase resource.ReadSeekCloserResource:\n\t\trc, err := rr.ReadSeekCloser()\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\treturn rc, nil\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"cannot transform content of Resource of type %T\", r)\n\n\t}\n}\n","sourceCodeStart":819,"sourceCodeEnd":841,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/resources/transform.go#L819-L841","documentation":"Returned by contentReadSeekCloser when a resource being transformed does not implement resource.ReadSeekCloserResource. Transformations need a ReadSeeker to re-read content (e.g. for caching, integrity, multi-pass transforms); resources that only expose a one-shot reader cannot be transformed and hit the default branch with %T.","triggerScenarios":"Calling a transformation (TransformWithContext/Transform) on a resource type that does not implement ReadSeekCloserResource — for example a remote-only resource, a constructed resource without seek support, or a post-publish resource that wasn't wrapped with ReadSeekCloser capability.","commonSituations":"Passing a resource obtained from resources.GetRemote (without caching) into a transform that needs seek; wrapping a reader-only adapter as a resource; transforming a remote/headless bundle resource directly.","solutions":["Ensure the resource is seekable — materialize it first (e.g. fetch and cache the remote resource, or copy into a resource that implements ReadSeekCloserResource).","Use resources.Get followed by a clone/copy that supports ReadSeekCloser before transforming.","If implementing a custom resource type, implement resource.ReadSeekCloserResource (ReadSeekCloser() method) so it can be transformed."],"exampleFix":"// before\n{{ $r := resources.GetRemote \"https://example.com/style.css\" }}\n{{ $x := $r | minify }} // cannot transform content of Resource of type *remoteResource\n\n// after\n{{ $r := resources.GetRemote \"https://example.com/style.css\" | resources.Copy \"style.css\" }}\n{{ $x := $r | minify }}","handlingStrategy":"type-guard","validationCode":"// Guard that a resource is transformable (seekable) before transforming.\nfunc isTransformable(r resource.Resource) bool {\n    _, ok := r.(resource.ReadSeekCloserResource)\n    return ok\n}","typeGuard":"// Go type guard for ReadSeekCloserResource.\nfunc asSeekable(r resource.Resource) (resource.ReadSeekCloserResource, bool) {\n    s, ok := r.(resource.ReadSeekCloserResource)\n    return s, ok\n}","tryCatchPattern":null,"preventionTips":["Materialize remote/one-shot resources (resources.Copy / fetch+cache) before transforming.","When implementing custom resource types, implement ReadSeekCloserResource.","Check the interface before chaining many transforms to fail with a clearer message."],"tags":["resource","readseeker","transform","type-assertion","remote-resource"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}