{"record":{"id":"940df13d409b391b","repo":"go-delve/delve","slug":"invalid-filter-argument-s","errorCode":null,"errorMessage":"invalid filter argument: %s","messagePattern":"invalid filter argument: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"service/debugger/debugger.go","lineNumber":1364,"sourceCode":"\t\t\tbpi.Arguments = api.ConvertVars(vars)\n\t\t}\n\t}\n\tif bp.LoadLocals != nil {\n\t\tif locals, err := s.LocalVariables(*api.LoadConfigToProc(bp.LoadLocals)); err == nil {\n\t\t\tbpi.Locals = api.ConvertVars(locals)\n\t\t}\n\t}\n\treturn nil\n}\n\n// Sources returns a list of the source files for target binary.\nfunc (d *Debugger) Sources(filter string) ([]string, error) {\n\td.targetMutex.Lock()\n\tdefer d.targetMutex.Unlock()\n\n\tregex, err := regexp.Compile(filter)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"invalid filter argument: %s\", err.Error())\n\t}\n\n\tfiles := []string{}\n\tt := proc.ValidTargets{Group: d.target}\n\tfor t.Next() {\n\t\tfor _, f := range t.BinInfo().Sources {\n\t\t\tif regex.MatchString(f) {\n\t\t\t\tfiles = append(files, f)\n\t\t\t}\n\t\t}\n\t}\n\tsort.Strings(files)\n\tfiles = slices.Compact(files)\n\treturn files, nil\n}\n\n// Functions returns a list of functions in the target process.\nfunc (d *Debugger) Functions(filter string, followCalls int) ([]string, error) {","sourceCodeStart":1346,"sourceCodeEnd":1382,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/service/debugger/debugger.go#L1346-L1382","documentation":"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).","triggerScenarios":"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`.","commonSituations":"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.","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."],"exampleFix":"// before\nfiles, err := d.Sources(\"main(.go\") // invalid\n// after\npattern := regexp.QuoteMeta(\"main(.go\")\nfiles, err := d.Sources(pattern)","handlingStrategy":"validation","validationCode":"if _, err := regexp.Compile(filter); err != nil {\n    filter = regexp.QuoteMeta(filter) // fall back to literal match\n}","typeGuard":null,"tryCatchPattern":"files, err := d.Sources(filter)\nif err != nil && strings.Contains(err.Error(), \"invalid filter argument\") {\n    files, err = d.Sources(regexp.QuoteMeta(filter))\n}","preventionTips":["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."],"tags":["regex","input-validation","filters"],"backgroundTag":"invalid-regex","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}