{"record":{"id":"0cdfc64c5ecf314b","repo":"gohugoio/hugo","slug":"failed-to-compile-cache-buster-source-q-w","errorCode":null,"errorMessage":"failed to compile cache buster source %q: %w","messagePattern":"failed to compile cache buster source %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"config/commonConfig.go","lineNumber":411,"sourceCode":"\t// Trigger for files matching this regexp.\n\tSource string\n\n\t// Cache bust targets matching this regexp.\n\t// This regexp can contain group matches (e.g. $1) from the source regexp.\n\tTarget string\n\n\tcompiledSource func(string) func(string) bool\n}\n\nfunc (c *CacheBuster) CompileConfig(logger loggers.Logger) error {\n\tif c.compiledSource != nil {\n\t\treturn nil\n\t}\n\n\tsource := c.Source\n\tsourceRe, err := regexp.Compile(source)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to compile cache buster source %q: %w\", c.Source, err)\n\t}\n\ttarget := c.Target\n\tvar compileErr error\n\tdebugl := logger.Logger().WithLevel(logg.LevelDebug).WithField(loggers.FieldNameCmd, \"cachebuster\")\n\n\tc.compiledSource = func(s string) func(string) bool {\n\t\tm := sourceRe.FindStringSubmatch(s)\n\t\tmatchString := \"no match\"\n\t\tmatch := m != nil\n\t\tif match {\n\t\t\tmatchString = \"match!\"\n\t\t}\n\t\tdebugl.Logf(\"Matching %q with source %q: %s\", s, source, matchString)\n\t\tif !match {\n\t\t\treturn nil\n\t\t}\n\t\tgroups := m[1:]\n\t\tcurrentTarget := target","sourceCodeStart":393,"sourceCodeEnd":429,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/config/commonConfig.go#L393-L429","documentation":"The inner error of CacheBuster.CompileConfig: it compiles the `source` field as a Go regexp (regexp.Compile). If source is empty, regexp.Compile succeeds with a match-all-empty; failure means genuinely malformed regexp syntax. This is the leaf cause wrapped by error 273 when called from BuildConfig.CompileConfig's loop.","triggerScenarios":"A `[[build.cacheBusters]]` `source` with invalid Go regexp syntax (unbalanced paren, bad escape). Because the source regexp also drives capture groups substituted into `target`, malformed groups break target compilation too.","commonSituations":"Writing cache busters for asset fingerprinting/dev-server and using glob/PCRE syntax instead of RE2; unbalanced capture group.","solutions":["Validate `source` with Go regexp (RE2) semantics.","Ensure any `(` has a matching `)`; escape literal metacharacters.","Remember `target` can reference `$1`, `$2`... from source groups."],"exampleFix":"# before\n[[build.cacheBusters]]\nsource = \".git/.*\"\ntarget = \"\\.git\\\\.\"\n\n# after\n[[build.cacheBusters]]\nsource = \"\\.git/.*\"\ntarget = \"\\.git\\\\.\"","handlingStrategy":"validation","validationCode":"python3 - <<'PY'\nimport tomllib,re\ncfg=tomllib.loads(open('hugo.toml').read())\nfor cb in cfg.get('build',{}).get('cacheBusters',[]):\n    try: re.compile(cb['source'])\n    except re.error as e: print(f\"bad cacheBuster source {cb['source']!r}: {e}\")\nprint(\"cacheBuster source ok\")\nPY","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use Go RE2 regexp syntax for cacheBuster.source.","Balance capture groups; reference them as $1 in target.","Escape regex metacharacters intended literally."],"tags":["config","regexp","cache","build"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}