{"record":{"id":"8ce245699a7f6aa3","repo":"amir20/dozzle","slug":"invalid-regex-pattern-w","errorCode":null,"errorMessage":"invalid regex pattern: %w","messagePattern":"invalid regex pattern: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cloud/tools_logs.go","lineNumber":62,"sourceCode":"\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"invalid start time format (expected RFC3339): %w\", err)\n\t\t}\n\t\tstart = t\n\t}\n\tif args.End != \"\" {\n\t\tt, err := time.Parse(time.RFC3339, args.End)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"invalid end time format (expected RFC3339): %w\", err)\n\t\t}\n\t\tend = t\n\t}\n\n\tvar re *regexp.Regexp\n\tif args.Regex != \"\" {\n\t\tvar err error\n\t\tre, err = regexp.Compile(args.Regex)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"invalid regex pattern: %w\", err)\n\t\t}\n\t}\n\n\tctx, cancel := context.WithCancel(ctx)\n\tdefer cancel()\n\n\tlogCh, err := cs.LogsBetweenDates(ctx, start, end, container.STDOUT|container.STDERR)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to fetch logs: %w\", err)\n\t}\n\n\tconst maxLines = 100\n\tentries := make([]*pb.LogEntry, 0, maxLines)\n\tfor event := range logCh {\n\t\tmsg, matches := matchesFilters(event, &args, re)\n\t\tif !matches {\n\t\t\tcontinue\n\t\t}","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/amir20/dozzle/blob/d9463cbe21874e44ab79db6fa63e746ca7d22928/internal/cloud/tools_logs.go#L44-L80","documentation":"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.","triggerScenarios":"Calling fetch_container_logs with args.regex containing syntax Go's RE2 rejects: lookahead/lookbehind '(?=...)', '(?<=...)', backreferences '(\\1)', unmatched '(' or '[', or invalid group names.","commonSituations":"Patterns copied from PCRE/JavaScript contexts using lookarounds; accidentally unescaped regex metacharacters from user input; unbalanced delimiters from string concatenation.","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"],"exampleFix":"// before\n{\"regex\":\"level=(?:(?:error|warn))\"}  // ok, but:\n{\"regex\":\"(?<=level=)error\"}        // invalid: lookbehind unsupported\n// after\n{\"regex\":\"level=error\"}","handlingStrategy":"validation","validationCode":"function isRE2Safe(pattern) { try { new RegExp(pattern.replace(/\\(\\?<?[=!]/g, '(?')); return !/\\\\[1-9]|\\(\\?</.test(pattern); } catch { return false; } }\nif (args.regex && !isRE2Safe(args.regex)) throw new Error('regex must be RE2-compatible: no lookarounds/backreferences');","typeGuard":"null","tryCatchPattern":null,"preventionTips":["Avoid lookarounds (?=) (?!) (?<=) and backreferences \\1","Escape literal metacharacters","Prefer the level/query filters over regex when possible"],"tags":["cloud-tools","regex","validation"],"backgroundTag":"invalid-regex-pattern","analyzedSha":"d9463cbe21874e44ab79db6fa63e746ca7d22928","analyzedAt":"2026-09-07T10:08:55.855Z","contentChangedAt":"2026-09-07T10:08:55.855Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}