gohugoio/hugo · error
failed to compile ignoreFiles pattern %q: %s
Error message
failed to compile ignoreFiles pattern %q: %s
What it means
`ignoreFiles` entries are compiled as Go (RE2) regular expressions used to skip content/asset files. If `regexp.Compile` rejects a pattern, config compilation fails with this error, naming the bad pattern and the regexp error.
Source
Thrown at config/allconfig/allconfig.go:375
case bool:
return v
case map[string]bool:
return v[section]
default:
return false
}
}
ignoreFile := func(s string) bool {
return false
}
if len(c.IgnoreFiles) > 0 {
regexps := make([]*regexp.Regexp, len(c.IgnoreFiles))
for i, pattern := range c.IgnoreFiles {
var err error
regexps[i], err = regexp.Compile(pattern)
if err != nil {
return fmt.Errorf("failed to compile ignoreFiles pattern %q: %s", pattern, err)
}
}
ignoreFile = func(s string) bool {
for _, r := range regexps {
if r.MatchString(s) {
return true
}
}
return false
}
}
var clock time.Time
if c.Internal.Clock != "" {
var err error
clock, err = time.Parse(time.RFC3339, c.Internal.Clock)
if err != nil {
return fmt.Errorf("failed to parse clock: %s", err)View on GitHub ↗ (pinned to 8a468df065)
Solutions
- Fix the regex syntax; remember these are RE2 regular expressions, not globs — use `\\.tmp$` not `*.tmp`.
- Remove PCRE-only constructs (lookaround, backreferences); restructure the pattern with alternation instead.
- Escape literal special characters in paths: `content/\\(drafts\\)/`.
- Test the pattern quickly with `go doc regexp/syntax` rules or an RE2-compatible tester.
Example fix
# before ignoreFiles = ["*.tmp", "(?!keep).*\\.bak"] # after ignoreFiles = ["\\.tmp$", "\\.bak$"]
Defensive patterns
Strategy: validation
Validate before calling
for _, pat := range ignoreFiles {
if _, err := regexp.Compile(pat); err != nil {
return fmt.Errorf("ignoreFiles pattern %q: %w", pat, err)
}
} Prevention
- Remember ignoreFiles entries are regular expressions, not globs — escape dots and don't use "*.md"
- Test each pattern with regexp.Compile (patterns are matched case-insensitively) before shipping config
- Prefer simple anchored patterns like "\\.foo$"
When it happens
Trigger: An `ignoreFiles` entry with invalid RE2 syntax — unbalanced parentheses/brackets, or PCRE-only constructs like lookaheads `(?!...)` or backreferences `\1`, which Go's regexp does not support.
Common situations: Users writing glob patterns (`*.tmp`) that happen to be invalid regexes or match unintended files, copying PCRE patterns from other tools, or unescaped special characters in file paths (e.g. `.` or `(` in directory names).
Related errors
- language %q not found
- unsupported format: %q
- filename not match
- failed to create workingDir: %w
- conf must be set
AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31).
Data as JSON: /data/errors/66e7e0753acad34d.json.
Report an issue: GitHub ↗.