{"record":{"id":"8352e4c3b934c81c","repo":"gohugoio/hugo","slug":"invalid-slice-type-t-8352e4","errorCode":null,"errorMessage":"invalid slice type %T","messagePattern":"invalid slice type %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"resources/resource.go","lineNumber":300,"sourceCode":"// for the template functions. See collections.Slice.\nfunc (commonResource) Slice(in any) (any, error) {\n\tswitch items := in.(type) {\n\tcase resource.Resources:\n\t\treturn items, nil\n\tcase []any:\n\t\tgroups := make(resource.Resources, len(items))\n\t\tfor i, v := range items {\n\t\t\tg, ok := v.(resource.Resource)\n\t\t\tif !ok {\n\t\t\t\treturn nil, fmt.Errorf(\"type %T is not a Resource\", v)\n\t\t\t}\n\t\t\tgroups[i] = g\n\t\t\t{\n\t\t\t}\n\t\t}\n\t\treturn groups, nil\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"invalid slice type %T\", items)\n\t}\n}\n\ntype fileInfo interface {\n\tsetOpenSource(hugio.OpenReadSeekCloser)\n\tsetSourceFilenameIsHash(bool)\n\tsetTargetPath(internal.ResourcePaths)\n\tsize() int64\n\thashProvider\n}\n\ntype hashProvider interface {\n\thash() uint64\n}\n\nvar _ resource.StaleInfo = (*StaleValue[any])(nil)\n\ntype StaleValue[V any] struct {","sourceCodeStart":282,"sourceCodeEnd":318,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/resources/resource.go#L282-L318","documentation":"Returned by `commonResource.Slice` when the argument is neither `resource.Resources` nor `[]any`. This is the `default` arm of the type switch at resource.go:299-301, hit when the caller passes a typed slice other than `Resources`, a single resource, a map, or a scalar.","triggerScenarios":"Calling the resource slice adapter with a `[]string`, `[]Page`, single `Resource` value, or any non-slice. The type switch only accepts `resource.Resources` and `[]any`.","commonSituations":"Template passes `.Page.Resources` typed as `page.Resources` (not `resource.Resources`) into a resource-collection helper; passing a single Resource where a list is expected; passing a typed Go slice through reflection.","solutions":["Coerce the input to `[]any` of Resources, or pass a `resource.Resources` value directly.","Use `collections.Slice` to normalize before calling resource helpers.","Verify the template variable holds a list of resources, not a single resource or a Page resource collection."],"exampleFix":"// template -- before\n{{ apply .Resources.ByType \"image/*\" \"resourceSlice\" }}\n\n// after\n{{ $imgs := .Resources.Match \"images/*\" }}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"func isResourceSlice(v any) bool {\n\tswitch v.(type) {\n\tcase resource.Resources, []any:\n\t\treturn true\n\t}\n\treturn false\n}","tryCatchPattern":null,"preventionTips":["Coerce typed slices to `[]any` via `collections.Slice` before calling resource adapters.","Avoid passing `page.Resources` to resource-side helpers."],"tags":["templates","resources","collections","type-mismatch"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}