{"record":{"id":"73b723a14a88c7ca","repo":"kubernetes/kubernetes","slug":"regexp-s-in-file-q-doesn-t-compile-w","errorCode":null,"errorMessage":"regexp `%s` in file %q doesn't compile: %w","messagePattern":"regexp `(.+?)` in file %q doesn't compile: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/import-boss/main.go","lineNumber":340,"sourceCode":"// unchanged. It returns the new path and the removed directory. So:\n// \"a/b/c/file\" -> (\"a/b/file\", \"c\")\nfunc removeLastDir(path string) (newPath, removedDir string) {\n\tdir, file := filepath.Split(path)\n\tdir = strings.TrimSuffix(dir, string(filepath.Separator))\n\treturn filepath.Join(filepath.Dir(dir), file), filepath.Base(dir)\n}\n\nfunc (boss *ImportBoss) verifyRules(pkg *packages.Package, restrictionFiles []*FileFormat) []error {\n\tklog.V(3).Infof(\"verifying pkg %q rules\", pkg.PkgPath)\n\n\t// compile all Selector regex in all restriction files\n\tselectors := make([][]*regexp.Regexp, len(restrictionFiles))\n\tfor i, restrictionFile := range restrictionFiles {\n\t\tfor _, r := range restrictionFile.Rules {\n\t\t\tre, err := regexp.Compile(r.SelectorRegexp)\n\t\t\tif err != nil {\n\t\t\t\treturn []error{\n\t\t\t\t\tfmt.Errorf(\"regexp `%s` in file %q doesn't compile: %w\", r.SelectorRegexp, restrictionFile.path, err),\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tselectors[i] = append(selectors[i], re)\n\t\t}\n\t}\n\n\trealPkgPath := unmassage(pkg.PkgPath)\n\n\tdirect, indirect := transitiveImports(pkg)\n\tisDirect := map[string]bool{}\n\tfor _, imp := range direct {\n\t\tisDirect[imp] = true\n\t}\n\trelate := func(imp string) string {\n\t\tif isDirect[imp] {\n\t\t\treturn \"->\"\n\t\t}","sourceCodeStart":322,"sourceCodeEnd":358,"githubUrl":"https://github.com/kubernetes/kubernetes/blob/b882c60b4023bdf09264c2d5d30a2cadebc240fb/cmd/import-boss/main.go#L322-L358","documentation":"Thrown in verifyRules (main.go:337-341) when regexp.Compile(rule.SelectorRegexp) fails for a Rule in the Rules list of a .import-restrictions file. import-boss aborts rule evaluation for that package because it cannot match imports against an uncompiled selector. The offending regex and the file path are both in the message.","triggerScenarios":"A selectorRegexp field contains invalid Go regexp (RE2) syntax: unescaped `(`, a dangling `*`, `[` without `]`, unsupported lookahead, etc. sigs.k8s.io/yaml accepted the string fine, but regexp.Compile rejects it.","commonSituations":"Copying a grep/PCRE regex with lookahead into selectorRegexp (RE2 has none); an unclosed character class like `[a-z`; a stray unbalanced parenthesis.","solutions":["Test the regex with an RE2 tester or a tiny Go regexp.Compile scratch program.","Use RE2 syntax: balance parens, escape literal dots (k8s[.]io), drop lookahead/lookbehind and backreferences.","Re-run import-boss after fixing."],"exampleFix":"# before -- RE2 rejects lookahead / unclosed class\nselectorRegexp: \"^(?!safe)k8s.io(.*\"\n# after\nselectorRegexp: \"^k8s[.]io/\"","handlingStrategy":"validation","validationCode":"for _, r := range ff.Rules {\n    if _, err := regexp.Compile(r.SelectorRegexp); err != nil {\n        return fmt.Errorf(\"%s: bad selectorRegexp %q: %w\", ff.path, r.SelectorRegexp, err)\n    }\n}","typeGuard":null,"tryCatchPattern":"re, err := regexp.Compile(r.SelectorRegexp)\nif err != nil {\n    return []error{fmt.Errorf(\"regexp `%s` in file %q doesn't compile: %w\", r.SelectorRegexp, restrictionFile.path, err)}\n}","preventionTips":["Validate all selectorRegexp values in a pre-commit hook before import-boss runs.","Remember import-boss uses Go's RE2: no backreferences, no lookahead.","Escape literal dots and parens in selectors."],"tags":["go","import-boss","kubernetes","regexp","config","linting"],"analyzedSha":"b882c60b4023bdf09264c2d5d30a2cadebc240fb","analyzedAt":"2026-08-07T04:07:48.144Z","schemaVersion":2},"datasetVersion":"2026-08-07T07:17:06.508Z"}