{"record":{"id":"a8c880aa81b8e725","repo":"grpc/grpc-go","slug":"invalid-method-name-should-start-with","errorCode":null,"errorMessage":"invalid method name: should start with /","messagePattern":"invalid method name: should start with /","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/grpcutil/method.go","lineNumber":30,"sourceCode":" * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n */\n\npackage grpcutil\n\nimport (\n\t\"errors\"\n\t\"strings\"\n)\n\n// ParseMethod splits service and method from the input. It expects format\n// \"/service/method\".\nfunc ParseMethod(methodName string) (service, method string, _ error) {\n\tif !strings.HasPrefix(methodName, \"/\") {\n\t\treturn \"\", \"\", errors.New(\"invalid method name: should start with /\")\n\t}\n\tmethodName = methodName[1:]\n\n\tpos := strings.LastIndex(methodName, \"/\")\n\tif pos < 0 {\n\t\treturn \"\", \"\", errors.New(\"invalid method name: suffix /method is missing\")\n\t}\n\treturn methodName[:pos], methodName[pos+1:], nil\n}\n\n// baseContentType is the base content-type for gRPC.  This is a valid\n// content-type on its own, but can also include a content-subtype such as\n// \"proto\" as a suffix after \"+\" or \";\".  See\n// https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md#requests\n// for more details.\nconst baseContentType = \"application/grpc\"\n\n// ContentSubtype returns the content-subtype for the given content-type.  The","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/grpc/grpc-go/blob/0c51461d27177d997e14c642fe18c11668fc09a3/internal/grpcutil/method.go#L12-L48","documentation":"Returned by grpcutil.ParseMethod when the method name does not start with '/'. gRPC method names follow the format '/package.Service/Method'—the leading slash is mandatory. ParseMethod strips it then splits on the last '/' to extract service and method names. This is an internal utility used by binary logging, observability, and stats handling to decompose the full method path.","triggerScenarios":"Calling ParseMethod with a string like 'package.Service/Method' (missing leading '/') or an empty/arbitrary string. Can happen if code constructs method names manually without the gRPC convention, or if a proxy/gateway rewrites the :path header and drops the leading slash.","commonSituations":"Custom interceptors or stats handlers that parse ctx.Value(methodKey) or full method paths; gRPC-Web or HTTP gateway proxies that mangle the request path; observability/binary-logging config pointing at malformed method names; programmatic construction of method strings.","solutions":["Ensure method names passed to ParseMethod always start with '/' (e.g., '/package.Service/Method').","If intercepting at the HTTP layer, verify proxies preserve the leading '/' in the :path pseudo-header.","Add a prefix '/' before calling ParseMethod if your string lacks it.","Log the raw method string to identify where the malformed name originates."],"exampleFix":"// before\nsvc, method, err := grpcutil.ParseMethod(\"myapp.UserService/GetUser\")\n// after\nsvc, method, err := grpcutil.ParseMethod(\"/myapp.UserService/GetUser\")","handlingStrategy":"validation","validationCode":"// Validate method name format before calling ParseMethod.\nfunc isValidMethodName(method string) bool {\n    return strings.HasPrefix(method, \"/\") && strings.Count(method, \"/\") >= 2\n}\nif !isValidMethodName(method) {\n    return errors.New(\"method must be '/package.Service/Method'\")\n}\nsvc, m, err := grpcutil.ParseMethod(method)","typeGuard":null,"tryCatchPattern":"svc, method, err := grpcutil.ParseMethod(name)\nif err != nil {\n    if strings.Contains(err.Error(), \"should start with /\") {\n        name = \"/\" + name\n        svc, method, err = grpcutil.ParseMethod(name)\n    }\n}","preventionTips":["Always construct gRPC method names with the leading '/' using the standard format.","Validate method strings from external sources before parsing.","Use grpc.MethodFromServerStream to get well-formed method names rather than constructing manually.","Log raw method names in interceptors to catch malformed values early."],"tags":["grpc","method-routing","internal","validation"],"backgroundTag":null,"analyzedSha":"0c51461d27177d997e14c642fe18c11668fc09a3","analyzedAt":"2026-08-11T14:49:15.055Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}