{"record":{"id":"45f4f2648bbe5d38","repo":"gohugoio/hugo","slug":"invalid-slice-type-t-45f4f2","errorCode":null,"errorMessage":"invalid slice type %T","messagePattern":"invalid slice type %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"resources/page/weighted.go","lineNumber":83,"sourceCode":"\n// Slice is for internal use.\n// for the template functions. See collections.Slice.\nfunc (p WeightedPage) Slice(in any) (any, error) {\n\tswitch items := in.(type) {\n\tcase WeightedPages:\n\t\treturn items, nil\n\tcase []any:\n\t\tweighted := make(WeightedPages, len(items))\n\t\tfor i, v := range items {\n\t\t\tg, ok := v.(WeightedPage)\n\t\t\tif !ok {\n\t\t\t\treturn nil, fmt.Errorf(\"type %T is not a WeightedPage\", v)\n\t\t\t}\n\t\t\tweighted[i] = g\n\t\t}\n\t\treturn weighted, nil\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"invalid slice type %T\", items)\n\t}\n}\n\n// Pages returns the Pages in this weighted page set.\nfunc (wp WeightedPages) Pages() Pages {\n\tpages := make(Pages, len(wp))\n\tfor i := range wp {\n\t\tpages[i] = wp[i].Page\n\t}\n\treturn pages\n}\n\n// Next returns the next Page relative to the given Page in\n// this weighted page set.\nfunc (wp WeightedPages) Next(cur Page) Page {\n\tfor x, c := range wp {\n\t\tif c.Page.Eq(cur) {\n\t\t\tif x == 0 {","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/resources/page/weighted.go#L65-L101","documentation":"Returned by `WeightedPage.Slice` when the argument is neither `WeightedPages` nor `[]any` -- i.e. the top-level type is unrecognized. This is the `default` arm of the type switch at weighted.go:82-84. It is an internal adapter used by `collections.Slice`; reaching it means the caller passed a struct, pointer, map, or scalar where a slice was required.","triggerScenarios":"A template or internal call passes a non-slice (a single Page, a string, a map, a `Pages` typed slice) into the WeightedPage Slice adapter. Because Go's type switch only matches `WeightedPages` and `[]any`, any concrete slice type like `[]Page` also falls through.","commonSituations":"Passing `site.GetPage ...` result (a single Page) where a list was expected; passing `Pages` (distinct from `WeightedPages`) into the weighted adapter; template helpers that return `interface{}` holding a typed slice.","solutions":["Wrap the argument so it is a `[]any` of WeightedPage values, or a `WeightedPages` value.","Use `collections.Slice` which normalizes inputs to `[]any` before dispatching.","Verify the template variable is a taxonomy/collection, not a single page, before calling."],"exampleFix":"// template -- before\n{{ apply .Page \"weightedSlice\" }}\n\n// after\n{{ apply .Site.Taxonomies.tags \"slice\" }}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"func isWeightedPages(v any) bool {\n\tswitch v.(type) {\n\tcase page.WeightedPages, []any:\n\t\treturn true\n\t}\n\treturn false\n}","tryCatchPattern":null,"preventionTips":["Pass `WeightedPages` or `[]any` -- never typed slices like `[]Page`.","Use `collections.Slice` to normalize before dispatching.","Don't pipe single values into list helpers."],"tags":["templates","weighted-page","collections","type-mismatch"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}