{"id":"952cac276d6d9840","repo":"gohugoio/hugo","slug":"failed-to-compile-cache-buster-q-w","errorCode":null,"errorMessage":"failed to compile cache buster %q: %w","messagePattern":"failed to compile cache buster %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"config/commonConfig.go","lineNumber":172,"sourceCode":"\t\t}\n\t}\n\tif len(matchers) > 0 {\n\t\treturn (func(cacheKey string) bool {\n\t\t\tfor _, m := range matchers {\n\t\t\t\tif m(cacheKey) {\n\t\t\t\t\treturn true\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn false\n\t\t}), nil\n\t}\n\treturn nil, nil\n}\n\nfunc (b *BuildConfig) CompileConfig(logger loggers.Logger) error {\n\tfor i, cb := range b.CacheBusters {\n\t\tif err := cb.CompileConfig(logger); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to compile cache buster %q: %w\", cb.Source, err)\n\t\t}\n\t\tb.CacheBusters[i] = cb\n\t}\n\treturn nil\n}\n\nfunc DecodeBuildConfig(cfg Provider) BuildConfig {\n\tm := cfg.GetStringMap(\"build\")\n\n\tb := defaultBuild.clone()\n\tif m == nil {\n\t\treturn b\n\t}\n\n\t// writeStats was a bool <= v0.115.0.\n\tif writeStats, ok := m[\"writestats\"]; ok {\n\t\tif bb, ok := writeStats.(bool); ok {\n\t\t\tm[\"buildstats\"] = BuildStats{Enable: bb}","sourceCodeStart":154,"sourceCodeEnd":190,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/config/commonConfig.go#L154-L190","documentation":"Raised by BuildConfig.CompileConfig in Hugo when one of the `build.cachebusters` entries fails to compile. Each CacheBuster carries a Source regexp (and a Target regexp compiled later); this wrapper error surfaces which cache buster entry is broken, wrapping the underlying compile error (typically the Source regexp failing regexp.Compile in CacheBuster.CompileConfig at config/commonConfig.go:411).","triggerScenarios":"Defining `[[build.cachebusters]]` in hugo.toml with an invalid Go (RE2) regular expression in the `source` field, e.g. `source = \"assets/*.(js\"` (unclosed group) or using PCRE-only syntax like lookaheads `(?=...)`, which Go's regexp package rejects. The error fires during config compilation at startup of `hugo` or `hugo server`.","commonSituations":"Copying cache buster examples and treating `source` as a glob instead of a regexp (e.g. writing `assets/**.js`); using lookahead/lookbehind or backreferences from PCRE which RE2 does not support; unescaped special characters like `(`, `[`, or `+` in file paths; typos introduced while customizing the default cachebusters from Hugo docs.","solutions":["Fix the `source` value of the named cache buster in `[[build.cachebusters]]` so it is a valid Go RE2 regexp — the error message quotes the offending pattern.","Escape regexp metacharacters in literal paths (e.g. `\\.` for dots) and remember `source` is a regexp, not a glob.","Remove PCRE-only constructs (lookarounds, backreferences); test the pattern at https://go.dev/play/ with regexp.Compile or on regex101 with the Golang flavor."],"exampleFix":"# before (hugo.toml)\n[[build.cachebusters]]\nsource = \"assets/*.(js\"\ntarget = \"(js|scss)\"\n\n# after\n[[build.cachebusters]]\nsource = \"assets/.*\\\\.(js|scss)$\"\ntarget = \"(js|scss)\"","handlingStrategy":"validation","validationCode":"// Validate cachebuster 'source' regexps before building config\nfor _, cb := range cfg.Build.CacheBusters {\n    if _, err := regexp.Compile(cb.Source); err != nil {\n        return fmt.Errorf(\"invalid cachebuster source %q: %w\", cb.Source, err)\n    }\n}","typeGuard":null,"tryCatchPattern":"cfg, err := allconfig.LoadConfig(...)\nif err != nil {\n    var msg = err.Error()\n    if strings.Contains(msg, \"failed to compile cache buster\") {\n        // report offending pattern to the user; do not proceed with build\n    }\n    return err\n}","preventionTips":["Treat cachebuster.source/target values in hugo.toml as Go RE2 regexps, not globs — test them with regexp.Compile or regex101 (Go flavor) before committing","Escape literal dots and slashes in patterns (e.g. `styles\\.css`)","Add a CI step that runs `hugo config` to fail fast on bad config before deploy"],"tags":["hugo","config","regexp","cache-buster","build"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}