amir20/dozzle · error
invalid regex pattern
Error message
invalid regex pattern: %w
What it means
If args.Regex is provided, it is compiled with regexp.Compile (Go/RE2 syntax). A pattern that fails to compile is wrapped as 'invalid regex pattern' with the RE2 error attached. This prevents an invalid filter from reaching the log stream.
Solutions
- Fix the pattern to valid RE2 syntax (no lookarounds or backreferences)
- Escape metacharacters literally intended, e.g. \. instead of .
- Test the pattern with Go's regexp.Compile or an RE2 playground before calling
- Drop the regex argument and rely on the level/query filter instead
Example fix
// before
{"regex":"level=(?:(?:error|warn))"} // ok, but:
{"regex":"(?<=level=)error"} // invalid: lookbehind unsupported
// after
{"regex":"level=error"} Defensive patterns
Strategy: validation
Validate before calling
function isRE2Safe(pattern) { try { new RegExp(pattern.replace(/\(\?<?[=!]/g, '(?')); return !/\\[1-9]|\(\?</.test(pattern); } catch { return false; } }
if (args.regex && !isRE2Safe(args.regex)) throw new Error('regex must be RE2-compatible: no lookarounds/backreferences'); Type guard
null
Prevention
- Avoid lookarounds (?=) (?!) (?<=) and backreferences \1
- Escape literal metacharacters
- Prefer the level/query filters over regex when possible
When it happens
Trigger: Calling fetch_container_logs with args.regex containing syntax Go's RE2 rejects: lookahead/lookbehind '(?=...)', '(?<=...)', backreferences '(\1)', unmatched '(' or '[', or invalid group names.
Common situations: Patterns copied from PCRE/JavaScript contexts using lookarounds; accidentally unescaped regex metacharacters from user input; unbalanced delimiters from string concatenation.
Related errors
- invalid regex pattern
- unknown action
- invalid start time format (expected RFC3339)
- invalid end time format (expected RFC3339)
- is required
AI-assisted analysis of amir20/dozzle@d9463cbe21 (2026-09-07).
Data as JSON: /api/errors/8ce245699a7f6aa3.
Report an issue: GitHub.
Appendix: source
Thrown at internal/cloud/tools_logs.go:62
if err != nil {
return nil, fmt.Errorf("invalid start time format (expected RFC3339): %w", err)
}
start = t
}
if args.End != "" {
t, err := time.Parse(time.RFC3339, args.End)
if err != nil {
return nil, fmt.Errorf("invalid end time format (expected RFC3339): %w", err)
}
end = t
}
var re *regexp.Regexp
if args.Regex != "" {
var err error
re, err = regexp.Compile(args.Regex)
if err != nil {
return nil, fmt.Errorf("invalid regex pattern: %w", err)
}
}
ctx, cancel := context.WithCancel(ctx)
defer cancel()
logCh, err := cs.LogsBetweenDates(ctx, start, end, container.STDOUT|container.STDERR)
if err != nil {
return nil, fmt.Errorf("failed to fetch logs: %w", err)
}
const maxLines = 100
entries := make([]*pb.LogEntry, 0, maxLines)
for event := range logCh {
msg, matches := matchesFilters(event, &args, re)
if !matches {
continue
}View on GitHub (pinned to d9463cbe21)