go-delve/delve · error

invalid Filter pattern

Error message

invalid Filter pattern: %v

What it means

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.

Solutions

  1. Validate the pattern with regexp.Compile before sending it over RPC and surface the error locally
  2. Convert glob patterns to regexp syntax: '*' -> '.*', escape '.' as '\\.'
  3. Escape user-supplied substrings with regexp.QuoteMeta when the intent is literal matching
  4. Remember Go uses RE2: remove PCRE-only constructs like backreferences or lookaheads

Example fix

// before
_, err := client.ListPackagesBuildInfo(rpc2.ListPackagesBuildInfoIn{Filter: "pkg/(net|http"}) // unbalanced paren
// after
if _, cerr := regexp.Compile("pkg/(net|http)"); cerr != nil {
    return cerr // fail fast client-side
}
_, err := client.ListPackagesBuildInfo(rpc2.ListPackagesBuildInfoIn{Filter: "pkg/(net|http)"})
Defensive patterns

Strategy: validation

Validate before calling

func validFilter(f string) error {
    if f == "" { return nil }
    _, err := regexp.Compile(f)
    return err
}
// call: if err := validFilter(in.Filter); err != nil { return err }

Try / catch

_, err := client.ListPackagesBuildInfo(rpc2.ListPackagesBuildInfoIn{Filter: pattern})
if err != nil && strings.Contains(err.Error(), "invalid Filter pattern") {
    return fmt.Errorf("bad --filter regexp: %w", err)
}

Prevention

When it happens

Trigger: 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'.

Common situations: 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).

Related errors


AI-assisted analysis of go-delve/delve@a23773e6c3 (2026-08-31). Data as JSON: /api/errors/c61a0580c6fdb6bf. Report an issue: GitHub.

Appendix: source

Thrown at service/rpc2/server.go:966

	Filter       string // if not empty, returns only packages matching the regexp.
}

// ListPackagesBuildInfoOut holds the return values of ListPackagesBuildInfo.
type ListPackagesBuildInfoOut struct {
	List []api.PackageBuildInfo
}

// ListPackagesBuildInfo returns the list of packages used by the program along with
// the directory where each package was compiled and optionally the list of
// files constituting the package.
// Note that the directory path is a best guess and may be wrong is a tool
// other than cmd/go is used to perform the build.
func (s *RPCServer) ListPackagesBuildInfo(in ListPackagesBuildInfoIn, out *ListPackagesBuildInfoOut) error {
	var pattern *regexp.Regexp
	if in.Filter != "" {
		p, err := regexp.Compile(in.Filter)
		if err != nil {
			return fmt.Errorf("invalid Filter pattern: %v", err)
		}
		pattern = p
	}
	pkgs := s.debugger.ListPackagesBuildInfo(in.IncludeFiles)
	out.List = make([]api.PackageBuildInfo, 0, len(pkgs))
	for _, pkg := range pkgs {
		if pattern != nil && !pattern.MatchString(pkg.ImportPath) {
			continue
		}
		var files []string

		if len(pkg.Files) > 0 {
			files = make([]string, 0, len(pkg.Files))
			for file := range pkg.Files {
				files = append(files, file)
			}
		}

View on GitHub (pinned to a23773e6c3)