gohugoio/hugo · error

failed to create filter for %s: %w

Error message

failed to create filter for %s: %w

What it means

While building an IntSets filter for a dimension (languages/versions/roles), NewIndexStringPredicateFromGlobsAndRanges failed to compile the provided glob/range patterns (vectorstores.go:806-808). This means the glob or range expression syntax itself is invalid, before any matching is attempted.

Source

Thrown at hugolib/sitesmatrix/vectorstores.go:808

			switch cfg.ApplyDefaults {
			case IntSetsConfigApplyDefaultsIfNotSet:
				result.Set(matcher.IndexDefault())
			case IntSetsConfigApplyDefaultsAndAllLanguagesIfNotSet:
				if what == "languages" {
					for i := range matcher.ForEachIndex() {
						result.Set(i)
					}
				} else {
					result.Set(matcher.IndexDefault())
				}
			}

			return result, nil
		}

		filter, err := predicate.NewIndexStringPredicateFromGlobsAndRanges(values, matcher.ResolveIndex, hglob.GetGlobDot)
		if err != nil {
			return nil, fmt.Errorf("failed to create filter for %s: %w", what, err)
		}
		iter, err := matcher.IndexMatch(filter)
		if err != nil {
			return nil, fmt.Errorf("failed to match %s %q: %w", what, values, err)
		}
		for i := range iter {
			if result == nil {
				result = hmaps.NewOrderedIntSet()
			}
			result.Set(i)
		}

		return result, nil
	}

	l, err1 := applyFilter("languages", cfg.Globs.Languages, b.cfg.ConfiguredLanguages)
	v, err2 := applyFilter("versions", cfg.Globs.Versions, b.cfg.ConfiguredVersions)
	r, err3 := applyFilter("roles", cfg.Globs.Roles, b.cfg.ConfiguredRoles)

View on GitHub (pinned to 52c9bd7908)

Solutions

  1. Check the value of cfg.Globs for the failing dimension (named in the error) and correct the glob/range syntax.
  2. Validate each pattern with the same glob library before feeding it to WithConfig.
  3. Simplify the filter to isolate the offending token, then rebuild incrementally.

Example fix

// before
cfg.Globs.Versions = []string{"1..0..0", "[invalid"}

// after
cfg.Globs.Versions = []string{"1.0.0", "v2.*"}
Defensive patterns

Strategy: validation

Validate before calling

// Pre-compile glob patterns to surface syntax errors before WithConfig.
func validateGlobs(patterns []string, resolve func(string) (int, error)) error {
    for _, p := range patterns {
        if _, err := predicate.NewIndexStringPredicateFromGlobsAndRanges([]string{p}, resolve, hglob.GetGlobDot); err != nil {
            return fmt.Errorf("invalid glob %q: %w", p, err)
        }
    }
    return nil
}

Prevention

When it happens

Trigger: Passing a malformed glob (unbalanced brackets, invalid range like '1-5-9') in cfg.Globs.Languages/Versions/Roles; a character sequence the glob compiler rejects. The 'what' field names which dimension failed.

Common situations: Typing a version range filter with bad syntax in config; copy-pasting a glob from a shell that uses characters Hugo's matcher disallows; programmatically assembling filter strings with unescaped special chars.

Related errors


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