amir20/dozzle · error
invalid regex pattern
Error message
invalid regex pattern: %w
What it means
parseStreamArgs compiles the optional regex argument with regexp.Compile; a syntactically invalid pattern yields 'invalid regex pattern' wrapping the Go regexp error. This prevents a bad pattern from reaching the streaming filter loop.
Solutions
- Fix the pattern to valid RE2 syntax per the wrapped compile error position
- Remove unsupported constructs (lookahead/lookbehind, backreferences) and rewrite the filter
- Omit the regex field entirely and rely on level/query filters if a pattern is not needed
Example fix
// before
parseStreamArgs(`{"container_id":"a1","regex":"(?<=err)\\d+"}`) // lookbehind unsupported
// after
parseStreamArgs(`{"container_id":"a1","regex":"err\\d+"}`) Defensive patterns
Strategy: validation
Validate before calling
if _, err := regexp.Compile(args.Regex); err != nil { /* fix pattern before sending */ } Try / catch
if err != nil && strings.Contains(err.Error(), "invalid regex pattern") {
// retry without regex or with corrected RE2 pattern
} Prevention
- Test patterns against Go RE2 (no lookahead/lookbehind/backreferences)
- Compile patterns client-side as a pre-check
- Fall back to level filters when regex is unnecessary
When it happens
Trigger: executeStreamLogs passes fetchLogsArgs with a non-empty Regex string that Go's regexp (RE2 syntax) cannot compile, e.g. unbalanced parentheses, invalid escape sequences, or lookahead assertions.
Common situations: LLM emitting PCRE-style patterns like '(?<=error )' which Go regexp rejects; typos such as 'error[' or 'foo).bar'; ported patterns from other languages using backreferences.
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/ea8f7fd58ecccb6a.
Report an issue: GitHub.
Appendix: source
Thrown at internal/cloud/tools_stream.go:33
// streamSender is a function that sends a ToolResponse to the cloud.
type streamSender func(resp *pb.ToolResponse) error
func parseStreamArgs(argsJSON string) (*fetchLogsArgs, *regexp.Regexp, error) {
var args fetchLogsArgs
if err := json.Unmarshal([]byte(argsJSON), &args); err != nil {
return nil, nil, fmt.Errorf("failed to parse arguments: %w", err)
}
if args.ContainerID == "" {
return nil, nil, fmt.Errorf("container_id is required")
}
var re *regexp.Regexp
if args.Regex != "" {
var err error
re, err = regexp.Compile(args.Regex)
if err != nil {
return nil, nil, fmt.Errorf("invalid regex pattern: %w", err)
}
}
return &args, re, nil
}
func matchesFilters(event *container.LogEvent, args *fetchLogsArgs, re *regexp.Regexp) (string, bool) {
if args.Level != "" && !strings.EqualFold(event.Level, args.Level) {
return "", false
}
msg := event.RawMessage
if msg == "" {
msg = fmt.Sprintf("%v", event.Message)
}
if args.Query != "" {
matched := containsIgnoreCase(msg, args.Query)
if matched == args.Inverse {View on GitHub (pinned to d9463cbe21)