{"record":{"id":"1bf34dc8d5a30f1d","repo":"grpc/grpc-go","slug":"q-contains-invalid-substring","errorCode":null,"errorMessage":"%q contains invalid substring","messagePattern":"%q contains invalid substring","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/binarylog/env_config.go","lineNumber":149,"sourceCode":"\theaderMessageConfigRegexpStr = `^{h` + optionalLengthRegexpStr + `;m` + optionalLengthRegexpStr + `}$`\n)\n\nvar (\n\tlongMethodConfigRegexp    = regexp.MustCompile(longMethodConfigRegexpStr)\n\theaderConfigRegexp        = regexp.MustCompile(headerConfigRegexpStr)\n\tmessageConfigRegexp       = regexp.MustCompile(messageConfigRegexpStr)\n\theaderMessageConfigRegexp = regexp.MustCompile(headerMessageConfigRegexpStr)\n)\n\n// Turn \"service/method{h;m}\" into \"service\", \"method\", \"{h;m}\".\nfunc parseMethodConfigAndSuffix(c string) (service, method, suffix string, _ error) {\n\t// Regexp result:\n\t//\n\t// in:  \"p.s/m{h:123,m:123}\",\n\t// out: []string{\"p.s/m{h:123,m:123}\", \"p.s\", \"m\", \"{h:123,m:123}\"},\n\tmatch := longMethodConfigRegexp.FindStringSubmatch(c)\n\tif match == nil {\n\t\treturn \"\", \"\", \"\", fmt.Errorf(\"%q contains invalid substring\", c)\n\t}\n\tservice = match[1]\n\tmethod = match[2]\n\tsuffix = match[3]\n\treturn\n}\n\n// Turn \"{h:123;m:345}\" into 123, 345.\n//\n// Return maxUInt if length is unspecified.\nfunc parseHeaderMessageLengthConfig(c string) (hdrLenStr, msgLenStr uint64, err error) {\n\tif c == \"\" {\n\t\treturn maxUInt, maxUInt, nil\n\t}\n\t// Header config only.\n\tif match := headerConfigRegexp.FindStringSubmatch(c); match != nil {\n\t\tif s := match[1]; s != \"\" {\n\t\t\thdrLenStr, err = strconv.ParseUint(s, 10, 64)","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/grpc/grpc-go/blob/0c51461d27177d997e14c642fe18c11668fc09a3/internal/binarylog/env_config.go#L131-L167","documentation":"Raised by parseMethodConfigAndSuffix when the method config token does not match the regex `^([\\w./]+)/((?:\\w+)|[*])(.+)?$`. The parser expects `service/method` or `service/method{suffix}` where the service allows word chars, dots, and slashes and the method is either a word or `*`. Any other shape produces this error.","triggerScenarios":"A token with no slash (e.g. `Foo`), a method containing illegal characters (e.g. `Foo/Bar-Baz`), a leading character other than `-`/`*`/word-char, or stray whitespace like ` Foo/Bar`. An empty token is caught earlier, but a token of only separators like `/Foo` also fails here.","commonSituations":"Typing a filter by hand with a hyphen, underscore-with-other-chars, or space; pasting a config with smart quotes or trailing commas that produce an empty/odd token; using a fully-qualified proto name with characters the regex disallows.","solutions":["Verify the offending token matches `service/method` (service: [\\w./]+, method: \\w+ or `*`).","Remove any whitespace, smart quotes, or stray commas around the token.","Escape or rename methods whose names use characters outside `\\w`; binary-log configs cannot express them.","Test the string by calling NewLoggerFromConfigString in a unit test and checking the warning output."],"exampleFix":"// before\nGRPC_BINARY_LOG_FILTER=\"Foo/Bar-Baz\"\n// after\nGRPC_BINARY_LOG_FILTER=\"Foo/BarBaz\"","handlingStrategy":"validation","validationCode":"var methodTokenRe = regexp.MustCompile(`^[\\w./]+/(?:\\w+|\\*)(?:\\{.*\\})?$`)\nfunc validMethodToken(tok string) bool {\n    tok = strings.TrimSpace(tok)\n    if tok == \"\" { return false }\n    if strings.HasPrefix(tok, \"-\") { tok = tok[1:] }\n    if strings.HasPrefix(tok, \"*\") { return true }\n    return methodTokenRe.MatchString(tok)\n}","typeGuard":null,"tryCatchPattern":"Loop over comma-split tokens and validate each with the regex above before passing the full string to NewLoggerFromConfigString; reject early with a clear error.","preventionTips":["Strip whitespace and empty tokens from filter strings before parsing.","Avoid method names with characters outside \\w; binary-log config cannot express them.","Keep a canonical example of each accepted token shape in your config docs."],"tags":["grpc","binary-log","config","parsing","regex"],"backgroundTag":null,"analyzedSha":"0c51461d27177d997e14c642fe18c11668fc09a3","analyzedAt":"2026-08-11T14:49:15.055Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}