go-delve/delve · error
invalid filter argument: %s
Error message
invalid filter argument: %s
What it means
Debugger.Sources interprets its filter argument as a Go regular expression and compiles it with regexp.Compile. If the filter is not a valid regex, the function returns "invalid filter argument: <regex error>" before listing any files. The wrapped text is the standard Go regexp parse error (e.g. missing closing parenthesis).
Source
Thrown at service/debugger/debugger.go:1364
bpi.Arguments = api.ConvertVars(vars)
}
}
if bp.LoadLocals != nil {
if locals, err := s.LocalVariables(*api.LoadConfigToProc(bp.LoadLocals)); err == nil {
bpi.Locals = api.ConvertVars(locals)
}
}
return nil
}
// Sources returns a list of the source files for target binary.
func (d *Debugger) Sources(filter string) ([]string, error) {
d.targetMutex.Lock()
defer d.targetMutex.Unlock()
regex, err := regexp.Compile(filter)
if err != nil {
return nil, fmt.Errorf("invalid filter argument: %s", err.Error())
}
files := []string{}
t := proc.ValidTargets{Group: d.target}
for t.Next() {
for _, f := range t.BinInfo().Sources {
if regex.MatchString(f) {
files = append(files, f)
}
}
}
sort.Strings(files)
files = slices.Compact(files)
return files, nil
}
// Functions returns a list of functions in the target process.
func (d *Debugger) Functions(filter string, followCalls int) ([]string, error) {View on GitHub (pinned to a23773e6c3)
Solutions
- Fix the regex: escape metacharacters, e.g. use `main\.go` and `\(test\)` where needed.
- Test the pattern with Go regexp semantics (regexp.QuoteMeta for literal strings).
- Pass an empty string or ".*" to list all sources without filtering.
- If interpolating paths, wrap them with regexp.QuoteMeta before calling Sources.
Example fix
// before
files, err := d.Sources("main(.go") // invalid
// after
pattern := regexp.QuoteMeta("main(.go")
files, err := d.Sources(pattern) Defensive patterns
Strategy: validation
Validate before calling
if _, err := regexp.Compile(filter); err != nil {
filter = regexp.QuoteMeta(filter) // fall back to literal match
} Try / catch
files, err := d.Sources(filter)
if err != nil && strings.Contains(err.Error(), "invalid filter argument") {
files, err = d.Sources(regexp.QuoteMeta(filter))
} Prevention
- QuoteMeta any literal file paths before using them as filters.
- Remember delve filters are regexes, not globs — no fnmatch syntax.
- Validate patterns with regexp.Compile before sending over RPC.
When it happens
Trigger: Calling Sources (RPC2 or terminal `sources`) with strings containing regex metacharacters meant literally: file paths with unescaped (, [, *, or a trailing backslash; e.g. `sources main(.go`.
Common situations: Users typing glob-style patterns (*.go, main[) instead of regex; paths copied from shells with parentheses; scripts interpolating unsanitized filenames into the filter; empty-ish patterns with stray operators.
Related errors
AI-assisted analysis of go-delve/delve@a23773e6c3 (2026-08-31).
Data as JSON: /api/errors/940df13d409b391b.
Report an issue: GitHub.