gohugoio/hugo · error
invalid argument type %T
Error message
invalid argument type %T
What it means
Pages.Related accepts either a related.Document (typically a Page) or a map of search options that is weak-decoded into related.SearchOpts. Any other argument type falls through the switch and is rejected with this error, because Hugo cannot infer what to search for.
Source
Thrown at resources/page/pages_related.go:69
}
// Related searches all the configured indices with the search keywords from the
// supplied document.
func (p Pages) Related(ctx context.Context, optsv any) (Pages, error) {
if len(p) == 0 {
return nil, nil
}
var opts related.SearchOpts
switch v := optsv.(type) {
case related.Document:
opts.Document = v
case map[string]any:
if err := mapstructure.WeakDecode(v, &opts); err != nil {
return nil, err
}
default:
return nil, fmt.Errorf("invalid argument type %T", optsv)
}
result, err := p.search(ctx, opts)
if err != nil {
return nil, err
}
return result, nil
}
// RelatedIndices searches the given indices with the search keywords from the
// supplied document.
// Deprecated: Use Related instead.
func (p Pages) RelatedIndices(ctx context.Context, doc related.Document, indices ...any) (Pages, error) {
indicesStr, err := cast.ToStringSliceE(indices)
if err != nil {
return nil, err
}View on GitHub ↗ (pinned to 8a468df065)
Solutions
- Pass the current page: `{{ $related := site.RegularPages.Related . }}`.
- For options, pass a dict: `{{ site.RegularPages.Related (dict "document" . "indices" (slice "tags")) }}`.
- If you were using `.RelatedIndices . "tags"` or `.RelatedTo (keyVals ...)`, either keep those deprecated methods or convert the arguments into the options dict form.
Example fix
<!-- before -->
{{ $related := site.RegularPages.Related "tags" }}
<!-- after -->
{{ $related := site.RegularPages.Related (dict "document" . "indices" (slice "tags")) }} Defensive patterns
Strategy: type-guard
Type guard
func relatedArg(v any) (any, bool) {
switch v.(type) {
case page.Page, []page.Page, page.Pages:
return v, true
default:
return nil, false
}
} Try / catch
{{ with .Site.RegularPages.Related . }}{{ range . }}...{{ end }}{{ end }} Prevention
- Pass the current Page (the `.` context) to .Related, not a string, map, or resource
- When using .RelatedTo, build the arg list with `keyVals`, not ad-hoc dicts
- Check the type of variables coming from partial params before calling Related
When it happens
Trigger: Calling `.Related` in a template with an argument that is neither a page nor an options map/dict — e.g. `{{ site.RegularPages.Related "tags" }}` (a string), a slice, a nil-ish value from a failed lookup, or a taxonomy term object. The %T in the message names the offending Go type.
Common situations: Migrating from the deprecated `.RelatedIndices`/`.RelatedTo` calling conventions and passing the old string/keyVals arguments to `.Related`; passing `.Params.something` that isn't a map; forgetting `(dict ...)` around options.
Related errors
- arguments to symdiff must be slices or arrays
- can't iterate over %T
- text must be a string
- first argument must be a map
- type %T not supported
AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31).
Data as JSON: /data/errors/71cc09c466dd8743.json.
Report an issue: GitHub ↗.