{"record":{"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":"exception","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/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/hugolib/segments/segments.go#L266-L302","documentation":"Raised by getGlob (segments.go:284) when hglob.GetGlob cannot compile a glob pattern from a segments config matchers field (kind, path, output). Hugo uses gobwas/glob; invalid pattern syntax — unbalanced brackets, stray metacharacters — surfaces here with the offending pattern quoted.","triggerScenarios":"A `[segments]` config entry whose `includes`/`excludes` lists contain a malformed glob: `[abc`, `**{`, unescaped special chars; patterns copied from a different glob dialect (e.g. gitignore) that gobwas/glob rejects.","commonSituations":"Writing segment filters for segmented builds with hand-crafted patterns; migrating glob syntax from another tool; negation prefix (`!`) applied to a pattern that itself is invalid.","solutions":["Open the wrapped error to see the glob parse detail, then fix the pattern (close brackets, escape special chars).","Use simple wildcard patterns (`posts/*`, `**/*.md`) that gobwas/glob accepts.","Test the pattern in isolation with gobwas/glob if unsure."],"exampleFix":"# before\n[segments]\n  [segments.posts]\n    [[segments.posts.includes]]\n      path = [\"posts[abc\"]\n\n# after\n      path = [\"posts/*\"]","handlingStrategy":"validation","validationCode":"# Sanity-check glob patterns in segments config (simple smoke test).\npython3 - <<'PY'\nimport re,sys\ntxt=open('hugo.toml').read()\nfor m in re.finditer(r'path\\s*=\\s*\\[([^\\]]+)\\]',txt):\n    for pat in re.findall(r'\"([^\"]+)\"',m.group(1)):\n        if '[' in pat and pat.count('[')!=pat.count(']'):\n            print('unbalanced glob:',pat)\nPY","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer simple wildcards (posts/*, **/*.md) over character classes in segment globs.","Test patterns with gobwas/glob before committing.","Keep segment matchers minimal; re-run a clean build after edits."],"tags":["segments","configuration","glob","validation"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}