{"record":{"id":"71cc09c466dd8743","repo":"gohugoio/hugo","slug":"invalid-argument-type-t","errorCode":null,"errorMessage":"invalid argument type %T","messagePattern":"invalid argument type %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"resources/page/pages_related.go","lineNumber":69,"sourceCode":"}\n\n// Related searches all the configured indices with the search keywords from the\n// supplied document.\nfunc (p Pages) Related(ctx context.Context, optsv any) (Pages, error) {\n\tif len(p) == 0 {\n\t\treturn nil, nil\n\t}\n\n\tvar opts related.SearchOpts\n\tswitch v := optsv.(type) {\n\tcase related.Document:\n\t\topts.Document = v\n\tcase map[string]any:\n\t\tif err := mapstructure.WeakDecode(v, &opts); err != nil {\n\t\t\treturn nil, err\n\t\t}\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"invalid argument type %T\", optsv)\n\t}\n\n\tresult, err := p.search(ctx, opts)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn result, nil\n}\n\n// RelatedIndices searches the given indices with the search keywords from the\n// supplied document.\n// Deprecated: Use Related instead.\nfunc (p Pages) RelatedIndices(ctx context.Context, doc related.Document, indices ...any) (Pages, error) {\n\tindicesStr, err := cast.ToStringSliceE(indices)\n\tif err != nil {\n\t\treturn nil, err\n\t}","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/resources/page/pages_related.go#L51-L87","documentation":"Thrown by Pages.Related when the options argument is neither a related.Document nor a map[string]any. The method uses a type switch with those two cases; any other type falls through to this error reporting the actual type.","triggerScenarios":"Calling .Related with the wrong argument, e.g. a string ('.Related \"tags\"'), a slice of keywords, or a struct that does not implement related.Document. The modern API expects either the current page (a Document) or an options map.","commonSituations":"Using the old positional RelatedIndices/RelatedTo calling convention against the newer Related method, or passing keyword arguments as a bare slice instead of types.KeyValues/options map.","solutions":["Pass the current page (a related.Document) for document-based search: {{ .RegularPages.Related . }}.","Pass a map[string]any options object for custom queries (e.g. {\"document\": ., \"indices\": [\"tags\"]}).","For keyword-based search use the deprecated RelatedTo with types.KeyValues, not Related."],"exampleFix":"{{/* before */}}\n{{ $r := .RegularPages.Related \"tags\" }}\n{{/* after */}}\n{{ $r := .RegularPages.Related . }}\n{{/* or options map */}}\n{{ $r := .RegularPages.Related (dict \"document\" . \"indices\" (slice \"tags\")) }}","handlingStrategy":"type-guard","validationCode":"switch optsv.(type) {\ncase related.Document, map[string]any:\n    // ok\ncinstance:\n    return fmt.Errorf(\"Related needs a Document or options map, got %T\", optsv)\n}","typeGuard":"func isRelatedArg(v any) bool {\n    switch v.(type) {\n    case related.Document, map[string]any:\n        return true\n    }\n    return false\n}","tryCatchPattern":"r, err := pages.Related(ctx, opts)\nif err != nil { /* log and return empty */ }","preventionTips":["Pass the current page (a related.Document) or an options map to Related.","Use RelatedTo with types.KeyValues for keyword-based searches.","Do not pass positional string arguments to Related."],"tags":["hugo","related-content","type-mismatch","templating"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}