{"record":{"id":"b9f8fd93b7fe6cbf","repo":"getsops/sops","slug":"can-not-compile-regexp-w","errorCode":null,"errorMessage":"can not compile regexp: %w","messagePattern":"can not compile regexp: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"config/config.go","lineNumber":593,"sourceCode":"\n\tconfigDir, err := filepath.Abs(filepath.Dir(confPath))\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\t// compare file path relative to path of config file\n\tfilePath = strings.TrimPrefix(filePath, configDir+string(filepath.Separator))\n\n\tvar rule *creationRule\n\n\tfor _, r := range conf.CreationRules {\n\t\tif r.PathRegex == \"\" {\n\t\t\trule = &r\n\t\t\tbreak\n\t\t}\n\t\treg, err := regexp.Compile(r.PathRegex)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"can not compile regexp: %w\", err)\n\t\t}\n\t\tif reg.MatchString(filePath) {\n\t\t\trule = &r\n\t\t\tbreak\n\t\t}\n\t}\n\n\tif rule == nil {\n\t\treturn nil, fmt.Errorf(\"error loading config: no matching creation rules found\")\n\t}\n\n\tconfig, err := configFromRule(rule, kmsEncryptionContext)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn config, nil\n}","sourceCodeStart":575,"sourceCodeEnd":611,"githubUrl":"https://github.com/getsops/sops/blob/13442bb98183887d7a9ac09ec8ab0564673a59d8/config/config.go#L575-L611","documentation":"Creation rules carry a path_regex used to match the file being encrypted/decrypted. sops compiles each rule's PathRegex with regexp.Compile and wraps any Go regexp syntax error in this message. An invalid regular expression in the config makes the whole rule unusable.","triggerScenarios":"A creation_rules (or destination rule lookup) entry has a path_regex with invalid syntax, e.g. an unbalanced parenthesis, dangling '*', bad escape like '\\d' in Go RE2 (must be '[0-9]' or '\\\\d' in YAML), or unclosed character class.","commonSituations":"Regex written for PCRE/JS engines but pasted into sops (Go uses RE2); unescaped dots or slashes; YAML single vs double quoting stripping backslashes incorrectly.","solutions":["Validate the regex with a RE2-compatible checker (regex101 with Golang flavor) before putting it in config","Escape properly: use '[0-9]' instead of '\\d', and quote the regex in YAML with single quotes so backslashes survive","Test the exact pattern with go: regexp.MatchString or sops editorconfig-checker style dry run","Start from a known-good pattern like path_regex: '\\.ya?ml$' and extend incrementally"],"exampleFix":"# before (invalid in RE2)\n- path_regex: '\\d+/secrets/.*'\n# after\n- path_regex: '[0-9]+/secrets/.*'","handlingStrategy":"validation","validationCode":"if _, err := regexp.Compile(rule.PathRegex); err != nil {\n    return fmt.Errorf(\"invalid path_regex %q in creation rule: %w\", rule.PathRegex, err)\n}","typeGuard":null,"tryCatchPattern":"cfg, err := loadConfigFile(confPath)\nif err != nil && strings.Contains(err.Error(), \"can not compile regexp\") {\n    return fmt.Errorf(\"fix path_regex syntax (Go RE2) in %s: %w\", confPath, err)\n}","preventionTips":["Validate all path_regex entries with Go's regexp package (RE2) in a CI config check","Use single-quoted YAML strings so backslashes are preserved","Avoid PCRE-only syntax (\\d, lookaheads) — use RE2 equivalents like [0-9]","Test regexes on regex101 with the Golang flavor before committing"],"tags":["config","regex","validation","sops"],"backgroundTag":"invalid-regex-syntax","analyzedSha":"13442bb98183887d7a9ac09ec8ab0564673a59d8","analyzedAt":"2026-09-01T03:53:00.447Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}