{"id":"9d2710e152726e71","repo":"gohugoio/hugo","slug":"failed-to-compile-glob-q-w","errorCode":null,"errorMessage":"failed to compile Glob %q: %w","messagePattern":"failed to compile Glob %q: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"hugolib/segments/segments.go","lineNumber":284,"sourceCode":"\n// SegmentMatcherFields holds string slices of ordered filters for segment matching.\n// The Glob patterns can be negated by prefixing with \"! \".\n// The first match wins (either include or exclude).\ntype SegmentMatcherFields struct {\n\tKind   []string\n\tPath   []string\n\tOutput []string\n\tLang   string            // Deprecated: use Sites.Matrix instead.\n\tSites  sitesmatrix.Sites // Note that we only use Sites.Matrix for now.\n}\n\nfunc getGlob(s string) (glob.Glob, error) {\n\tif s == \"\" {\n\t\treturn nil, nil\n\t}\n\tg, err := hglob.GetGlob(s)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to compile Glob %q: %w\", s, err)\n\t}\n\treturn g, nil\n}\n\nfunc DecodeSegments(in map[string]any, segmentsToRender []string, logger loggers.Logger) (*config.ConfigNamespace[map[string]SegmentConfig, *Segments], error) {\n\tbuildConfig := func(in any) (*Segments, any, error) {\n\t\tm, err := hmaps.ToStringMapE(in)\n\t\tif err != nil {\n\t\t\treturn nil, nil, err\n\t\t}\n\t\tif m == nil {\n\t\t\tm = map[string]any{}\n\t\t}\n\t\tm = hmaps.CleanConfigStringMap(m)\n\n\t\tvar segmentCfg map[string]SegmentConfig\n\t\tif err := mapstructure.WeakDecode(m, &segmentCfg); err != nil {\n\t\t\treturn nil, nil, err","sourceCodeStart":266,"sourceCodeEnd":302,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/hugolib/segments/segments.go#L266-L302","documentation":"Raised by `getGlob` in hugolib/segments/segments.go:284 when compiling a pattern from the `segments` site configuration. Segment matcher fields (`kind`, `path`, `output`) are glob patterns (compiled via Hugo's glob helper, optionally negated with a leading \"! \"); a syntactically invalid glob aborts config decoding for the segments namespace.","triggerScenarios":"Defining `[segments.<name>]` includes/excludes whose `path`, `kind`, or `output` entries contain an invalid glob — e.g. an unclosed character class `[abc`, an unclosed brace group `{a,b`, or a stray escape at end of pattern — then running any hugo command that loads config (`hugo`, `hugo server --renderSegments`).","commonSituations":"Writing regex syntax where a glob is expected (segments use globs, unlike deployment matchers which use regexes); unbalanced `{}` alternation groups in path patterns like `/blog/{a,b`; typoed character classes; confusion introduced when copying patterns between config sections.","solutions":["Fix the quoted pattern in the error: segments patterns are globs, so use `**` / `*` / `{a,b}` syntax, not regex (`.*`, anchors, backreferences).","Balance any `{...}` groups and `[...]` classes in the pattern.","Test by removing the segment definition and re-adding patterns one at a time to isolate the bad one."],"exampleFix":"# before\n[segments.docs]\n  [[segments.docs.includes]]\n  path = \"/docs/{intro,guide\"\n\n# after\n[segments.docs]\n  [[segments.docs.includes]]\n  path = \"/docs/{intro,guide}/**\"","handlingStrategy":"validation","validationCode":"import \"github.com/gobwas/glob\"\nif _, err := glob.Compile(pattern, '/'); err != nil {\n    return fmt.Errorf(\"segments filter glob %q: %w\", pattern, err)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Segment filter fields (path, lang, kind, output) are globs — balance brackets/braces (`{a,b}`, `[ab]`) and escape literal special chars","Test segment config with a fast local build (`hugo --renderSegments <name>`) before relying on it in CI","Keep patterns simple (`/blog/**`) and add complexity only when needed"],"tags":["hugo","segments","glob","config-validation"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}