gohugoio/hugo · error

can't evaluate the array by no match argument or more than o

Error message

can't evaluate the array by no match argument or more than or equal to two arguments

What it means

parseWhereArgs hit its default case: after the collection and key, `where` accepts either one argument (a match value) or two (operator + match value). Zero trailing args or three-plus is unparseable, so Hugo refuses to evaluate the filter. The message wording is awkward but means 'wrong number of arguments'.

Source

Thrown at tpl/collections/where.go:402

	return zero, fmt.Errorf("%s is neither a struct field, a method nor a map element of type %s", elemName, typ)
}

// parseWhereArgs parses the end arguments to the where function.  Return a
// match value and an operator, if one is defined.
func parseWhereArgs(args ...any) (mv reflect.Value, op string, err error) {
	switch len(args) {
	case 1:
		mv = reflect.ValueOf(args[0])
	case 2:
		var ok bool
		if op, ok = args[0].(string); !ok {
			err = errors.New("operator argument must be string type")
			return
		}
		op = strings.TrimSpace(strings.ToLower(op))
		mv = reflect.ValueOf(args[1])
	default:
		err = errors.New("can't evaluate the array by no match argument or more than or equal to two arguments")
	}
	return
}

// elemResolver resolves a sub-element from a reflect.Value.
// Built once before the loop to avoid repeated type checks and reflect.ValueOf allocations.
type elemResolver func(reflect.Value) (reflect.Value, error)

// newElemResolver returns a resolver optimized for the given element type and path.
// Returns nil if optimization isn't possible, in which case the caller should
// fall back to evaluateSubElem.
func (ns *Namespace) newElemResolver(ctxv reflect.Value, elemType reflect.Type, path []string) elemResolver {
	if elemType.Kind() == reflect.Interface {
		if len(path) != 1 {
			return nil
		}
		return ns.newInterfaceMethodResolver(ctxv, elemType, path[0])
	}

View on GitHub ↗ (pinned to 8a468df065)

Solutions

  1. Provide exactly one match value: `where .Site.Pages "Section" "blog"`.
  2. For an operator form, use exactly operator + value: `where .Pages "Params.n" ">" 3`.
  3. When piping, remember the piped value becomes the last argument — restructure the call accordingly.

Example fix

<!-- before -->
{{ range where .Site.RegularPages "Section" }}
<!-- after -->
{{ range where .Site.RegularPages "Section" "blog" }}
Defensive patterns

Strategy: validation

Validate before calling

{{/* call where with exactly 3 or 4 args */}}
{{ $r := where $pages "Section" "blog" }}
{{ $r2 := where $pages "Params.year" ">=" 2024 }}

Prevention

When it happens

Trigger: Calling `where` with only a collection and key (`where .Site.Pages "Section"`), or with extra arguments (`where .Pages "Section" "eq" "blog" "extra"`), often from a piped expression injecting an extra arg.

Common situations: Forgetting the match value; piping into where (`$x | where "k" "v1" "v2"` adds the piped value as a final arg); copy-paste leaving stray arguments.

Related errors


AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31). Data as JSON: /data/errors/a5662a04b60c87b4.json. Report an issue: GitHub ↗.