{"record":{"id":"a14d02fd3ed99051","repo":"gohugoio/hugo","slug":"failed-to-apply-filters-w","errorCode":null,"errorMessage":"failed to apply filters: %w","messagePattern":"failed to apply filters: %w","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"hugolib/sitesmatrix/vectorstores.go","lineNumber":829,"sourceCode":"\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to match %s %q: %w\", what, values, err)\n\t\t}\n\t\tfor i := range iter {\n\t\t\tif result == nil {\n\t\t\t\tresult = hmaps.NewOrderedIntSet()\n\t\t\t}\n\t\t\tresult.Set(i)\n\t\t}\n\n\t\treturn result, nil\n\t}\n\n\tl, err1 := applyFilter(\"languages\", cfg.Globs.Languages, b.cfg.ConfiguredLanguages)\n\tv, err2 := applyFilter(\"versions\", cfg.Globs.Versions, b.cfg.ConfiguredVersions)\n\tr, err3 := applyFilter(\"roles\", cfg.Globs.Roles, b.cfg.ConfiguredRoles)\n\n\tif err := cmp.Or(err1, err2, err3); err != nil {\n\t\tpanic(fmt.Errorf(\"failed to apply filters: %w\", err))\n\t}\n\n\tb.GlobFilterMisses = Bools{\n\t\tlen(cfg.Globs.Languages) > 0 && l == nil,\n\t\tlen(cfg.Globs.Versions) > 0 && v == nil,\n\t\tlen(cfg.Globs.Roles) > 0 && r == nil,\n\t}\n\n\tb.s.languages = l\n\tb.s.versions = v\n\tb.s.roles = r\n\n\treturn b\n}\n\nfunc (s *IntSetsBuilder) WithLanguageIndices(idxs ...int) *IntSetsBuilder {\n\tif len(idxs) == 0 {\n\t\treturn s","sourceCodeStart":811,"sourceCodeEnd":847,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/hugolib/sitesmatrix/vectorstores.go#L811-L847","documentation":"IntSetsBuilder.WithConfig applies three filters (languages, versions, roles) via applyFilter and, if any returned an error, panics with a wrapped %w (vectorstores.go:828-830). This treats filter setup failure as a programmer error/invariant violation rather than a recoverable condition. The underlying cause is one of the 'failed to create filter' or 'failed to match' errors.","triggerScenarios":"Any invalid glob/range pattern or unresolvable dimension name in cfg.Globs passed to IntSetsBuilder.WithConfig triggers the panic via the applyFilter error path. Because callers don't expect an error return from WithConfig, it panics.","commonSituations":"Constructing an IntSetsBuilder programmatically with user-supplied filter strings without prior validation; a config refactor that introduces a bad default glob.","solutions":["Validate all glob/range patterns and dimension names BEFORE calling WithConfig (pre-compile with the same predicate library).","Ensure WithConfig only receives filters referencing configured dimensions.","Wrap builder construction in a recover() during development to capture the wrapped error for diagnosis.","Treat any occurrence as a bug in the calling code's input validation."],"exampleFix":"// before\nb := builder.WithConfig(IntSetsConfig{Globs: IntSetsGlobs{Languages: []string{\"[bad\"}}}) // panics\n\n// after: validate first\nfor _, g := range globs.Languages {\n    if _, err := predicate.NewIndexStringPredicateFromGlobsAndRanges([]string{g}, langs.ResolveIndex, hglob.GetGlobDot); err != nil {\n        return err\n    }\n}\nb := builder.WithConfig(IntSetsConfig{Globs: globs})","handlingStrategy":"validation","validationCode":"// Validate all three dimensions' globs BEFORE calling WithConfig to avoid the panic.\nfunc safeWithConfig(b *IntSetsBuilder, cfg IntSetsConfig, c *ConfiguredDimensions) (*IntSetsBuilder, error) {\n    checks := []struct{ name string; vals []string; m ConfiguredDimension }{\n        {\"languages\", cfg.Globs.Languages, c.ConfiguredLanguages},\n        {\"versions\", cfg.Globs.Versions, c.ConfiguredVersions},\n        {\"roles\",     cfg.Globs.Roles,     c.ConfiguredRoles},\n    }\n    for _, ck := range checks {\n        for _, g := range ck.vals {\n            if _, err := predicate.NewIndexStringPredicateFromGlobsAndRanges([]string{g}, ck.m.ResolveIndex, hglob.GetGlobDot); err != nil {\n                return nil, fmt.Errorf(\"invalid %s glob %q: %w\", ck.name, g, err)\n            }\n        }\n    }\n    return b.WithConfig(cfg), nil\n}","typeGuard":null,"tryCatchPattern":"// During development, wrap WithConfig to capture the panic as an error.\nfunc recoverWithConfig(b *IntSetsBuilder, cfg IntSetsConfig) (out *IntSetsBuilder, err error) {\n    defer func() {\n        if r := recover(); r != nil {\n            err = fmt.Errorf(\"WithConfig panic: %v\", r)\n        }\n    }()\n    return b.WithConfig(cfg), nil\n}","preventionTips":["Never pass unvalidated user/config glob strings to WithConfig.","Pre-compile each glob with the predicate library in a helper before building.","Treat a panic here as an input-validation bug in the caller."],"tags":["sitesmatrix","panic","filter","validation"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}