{"record":{"id":"c61a0580c6fdb6bf","repo":"go-delve/delve","slug":"invalid-filter-pattern-v","errorCode":null,"errorMessage":"invalid Filter pattern: %v","messagePattern":"invalid Filter pattern: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"service/rpc2/server.go","lineNumber":966,"sourceCode":"\tFilter       string // if not empty, returns only packages matching the regexp.\n}\n\n// ListPackagesBuildInfoOut holds the return values of ListPackagesBuildInfo.\ntype ListPackagesBuildInfoOut struct {\n\tList []api.PackageBuildInfo\n}\n\n// ListPackagesBuildInfo returns the list of packages used by the program along with\n// the directory where each package was compiled and optionally the list of\n// files constituting the package.\n// Note that the directory path is a best guess and may be wrong is a tool\n// other than cmd/go is used to perform the build.\nfunc (s *RPCServer) ListPackagesBuildInfo(in ListPackagesBuildInfoIn, out *ListPackagesBuildInfoOut) error {\n\tvar pattern *regexp.Regexp\n\tif in.Filter != \"\" {\n\t\tp, err := regexp.Compile(in.Filter)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"invalid Filter pattern: %v\", err)\n\t\t}\n\t\tpattern = p\n\t}\n\tpkgs := s.debugger.ListPackagesBuildInfo(in.IncludeFiles)\n\tout.List = make([]api.PackageBuildInfo, 0, len(pkgs))\n\tfor _, pkg := range pkgs {\n\t\tif pattern != nil && !pattern.MatchString(pkg.ImportPath) {\n\t\t\tcontinue\n\t\t}\n\t\tvar files []string\n\n\t\tif len(pkg.Files) > 0 {\n\t\t\tfiles = make([]string, 0, len(pkg.Files))\n\t\t\tfor file := range pkg.Files {\n\t\t\t\tfiles = append(files, file)\n\t\t\t}\n\t\t}\n","sourceCodeStart":948,"sourceCodeEnd":984,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/service/rpc2/server.go#L948-L984","documentation":"ListPackagesBuildInfo throws this when the optional Filter field is not a valid Go regular expression. The handler compiles in.Filter with regexp.Compile before filtering packages, and compilation failure is reported with the underlying regexp error.","triggerScenarios":"Calling RPCClient.ListPackagesBuildInfo with ListPackagesBuildInfoIn.Filter set to a syntactically invalid regexp, e.g. unbalanced parentheses '(' , a dangling '*' as the first character, or a bad escape like '\\q'.","commonSituations":"Users typing glob-style filters ('pkg/*' instead of 'pkg/.*') into tooling that passes them straight through as regexps; programmatically-built filters where user input is interpolated unescaped; patterns copied from grep/sed with syntax Go's RE2 rejects (e.g. backreferences).","solutions":["Validate the pattern with regexp.Compile before sending it over RPC and surface the error locally","Convert glob patterns to regexp syntax: '*' -> '.*', escape '.' as '\\\\.'","Escape user-supplied substrings with regexp.QuoteMeta when the intent is literal matching","Remember Go uses RE2: remove PCRE-only constructs like backreferences or lookaheads"],"exampleFix":"// before\n_, err := client.ListPackagesBuildInfo(rpc2.ListPackagesBuildInfoIn{Filter: \"pkg/(net|http\"}) // unbalanced paren\n// after\nif _, cerr := regexp.Compile(\"pkg/(net|http)\"); cerr != nil {\n    return cerr // fail fast client-side\n}\n_, err := client.ListPackagesBuildInfo(rpc2.ListPackagesBuildInfoIn{Filter: \"pkg/(net|http)\"})","handlingStrategy":"validation","validationCode":"func validFilter(f string) error {\n    if f == \"\" { return nil }\n    _, err := regexp.Compile(f)\n    return err\n}\n// call: if err := validFilter(in.Filter); err != nil { return err }","typeGuard":null,"tryCatchPattern":"_, err := client.ListPackagesBuildInfo(rpc2.ListPackagesBuildInfoIn{Filter: pattern})\nif err != nil && strings.Contains(err.Error(), \"invalid Filter pattern\") {\n    return fmt.Errorf(\"bad --filter regexp: %w\", err)\n}","preventionTips":["Compile the filter client-side first to fail fast with a local error message","Use regexp.QuoteMeta for literal user input","Convert globs to RE2 syntax manually ('*' -> '.*')","Avoid PCRE-only features (backreferences, lookarounds) — Go regexp is RE2"],"tags":["rpc","regexp","validation","delve"],"backgroundTag":"invalid-regex-pattern","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}