gohugoio/hugo · error

invalid intersect values

Error message

invalid intersect values

What it means

When using the `intersect` operator inside `where`, Hugo calls `ns.Intersect(slv, slmv)` and expects the result to be a slice. If `reflect.TypeOf(r).Kind()` is not `reflect.Slice`, this error is returned. This is a defensive guard against an unexpected return type from Intersect — typically a sign that the operands were not valid comparable slices of the same element kind.

Solutions

  1. Ensure the key field on every element is a slice of a comparable type (e.g. `[]string`).
  2. Verify both operands are slices before using the intersect operator.
  3. If the field may be a single value, wrap it: `{{ where .Pages "Tags" "intersect" (slice $tag) }}` and ensure Tags is always a slice.

Example fix

// before
{{ where .Pages "Tags" "intersect" $singleTagString }}
// after
{{ where .Pages "Tags" "intersect" (slice $singleTagString) }}
Defensive patterns

Strategy: type-guard

Type guard

func isSliceOfSlices(v any) bool {
    rv := reflect.ValueOf(v)
    if rv.Kind() != reflect.Slice { return false }
    return rv.Type().Elem().Kind() == reflect.Slice
}

Prevention

When it happens

Trigger: Using the intersect operator in `where`, e.g. `{{ where .Pages "Tags" "intersect" $tagSlice }}`, where the key field does not resolve to a slice or the operands' element types are incompatible so Intersect cannot produce a slice result.

Common situations: A developer applies the `intersect` operator against a field that is sometimes a scalar (string) rather than a slice, or against a nil-valued field that yields a non-slice reflect.Value from Intersect.

Related errors


AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09). Data as JSON: /api/errors/bb99b05aad001c64. Report an issue: GitHub.

Appendix: source

Thrown at tpl/collections/where.go:294

		if op == "not in" {
			return !r, nil
		}
		return r, nil
	case "intersect":
		r, err := ns.Intersect(slv, slmv)
		if err != nil {
			return false, err
		}

		if reflect.TypeOf(r).Kind() == reflect.Slice {
			s := reflect.ValueOf(r)

			if s.Len() > 0 {
				return true, nil
			}
			return false, nil
		}
		return false, errors.New("invalid intersect values")
	case "like":
		if svp != nil && smvp != nil {
			re, err := hstrings.GetOrCompileRegexp(*smvp)
			if err != nil {
				return false, err
			}
			if re.MatchString(*svp) {
				return true, nil
			}
			return false, nil
		}
	default:
		return false, errors.New("no such operator")
	}
	return false, nil
}

func evaluateSubElem(ctx, obj reflect.Value, elemName string) (reflect.Value, error) {

View on GitHub (pinned to 52c9bd7908)