{"record":{"id":"14d9d1b6bcfa29ce","repo":"crowdsecurity/crowdsec","slug":"while-compiling-regexp-s-w","errorCode":null,"errorMessage":"while compiling regexp '%s': %w","messagePattern":"while compiling regexp '(.+?)': %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/acquisition/modules/cloudwatch/config.go","lineNumber":187,"sourceCode":"\t\tif s.Config.AwsRegion == \"\" {\n\t\t\ts.logger.Errorf(\"aws_region is not specified, specify it or aws_config_dir\")\n\t\t\treturn errors.New(\"aws_region is not specified, specify it or aws_config_dir\")\n\t\t}\n\n\t\tos.Setenv(\"AWS_REGION\", s.Config.AwsRegion)\n\t}\n\n\tif err := s.newClient(ctx); err != nil {\n\t\treturn err\n\t}\n\n\ts.streamIndexes = make(map[string]string)\n\n\ttargetStream := \"*\"\n\n\tif s.Config.StreamRegexp != nil {\n\t\tif _, err := regexp.Compile(*s.Config.StreamRegexp); err != nil {\n\t\t\treturn fmt.Errorf(\"while compiling regexp '%s': %w\", *s.Config.StreamRegexp, err)\n\t\t}\n\n\t\ttargetStream = *s.Config.StreamRegexp\n\t} else if s.Config.StreamName != nil {\n\t\ttargetStream = *s.Config.StreamName\n\t}\n\n\ts.logger.Infof(\"Adding cloudwatch group '%s' (stream:%s) to datasources\", s.Config.GroupName, targetStream)\n\n\treturn nil\n}\n\nfunc (s *Source) ConfigureByDSN(ctx context.Context, dsn string, labels map[string]string, logger *log.Entry, uuid string) error {\n\ts.logger = logger\n\n\tdsn = strings.TrimPrefix(dsn, s.GetName()+\"://\")\n\n\targs := strings.Split(dsn, \"?\")","sourceCodeStart":169,"sourceCodeEnd":205,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/acquisition/modules/cloudwatch/config.go#L169-L205","documentation":"The cloudwatch source compiles stream_regexp up-front with regexp.Compile to fail fast on invalid patterns before querying AWS. A malformed regular expression aborts source configuration with this wrapped error.","triggerScenarios":"Configure path (setupAWS) encountering a stream_regexp value that Go's regexp (RE2) cannot compile — e.g. unbalanced parentheses, invalid escape sequences like '\\d' being mis-escaped in YAML, or unsupported lookahead constructs.","commonSituations":"Copying PCRE-style regexes from other tools using unsupported features (lookaheads, backreferences), YAML escaping mangling backslashes ('\\d' vs '\\\\d'), or hand-edited config typos like a missing closing ')'.","solutions":["Fix the regexp syntax in stream_regexp; test it with a Go RE2-compatible checker.","Remove lookahead/lookbehind or backreference constructs unsupported by Go regexp.","Check YAML escaping: use single quotes ('\\d+') or double the backslash in double-quoted strings.","Pre-validate the pattern with regexp.Compile in a scratch Go program before editing the live config."],"exampleFix":"// before\nstream_regexp: \"(?=.*prod).*logs\"  # lookahead unsupported\n// after\nstream_regexp: \".*prod.*logs\"","handlingStrategy":"validation","validationCode":"if cfg.StreamRegexp != nil {\n    if _, err := regexp.Compile(*cfg.StreamRegexp); err != nil {\n        return fmt.Errorf(\"invalid stream_regexp: %w\", err)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := src.Configure(ctx, cfg); err != nil {\n    if strings.Contains(err.Error(), \"compiling regexp\") {\n        return fmt.Errorf(\"fix stream_regexp syntax: %w\", err)\n    }\n}","preventionTips":["Test regexes against Go RE2 (no lookahead/backreferences) before deploying","Quote regexes in YAML with single quotes to avoid backslash escaping issues","Lint acquis.yaml in CI with a compile check"],"tags":["aws","cloudwatch","regex","configuration"],"backgroundTag":"invalid-regex-pattern","analyzedSha":"909b5157986a2b2c2163300fdaef5ed01289f7d2","analyzedAt":"2026-09-06T12:27:26.012Z","contentChangedAt":"2026-09-06T12:27:26.012Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}