grpc/grpc-go · error
method name must be non empty
Error message
method name must be non empty
What it means
Returned by validateMethodString when the method part (the segment after the '/') is empty. The function splits by '/' and checks serviceMethod[1] == "". This catches patterns like pkg.Service/ where the service is specified but no method name follows the slash.
Solutions
- Provide a concrete method name (foo.Bar/Method) or use the wildcard (foo.Bar/*) to match all methods.
- Fix config-generation templates that append a trailing slash without a method suffix.
Example fix
// before
{"methods":["foo.Bar/"]} // trailing slash, empty method
// after
{"methods":["foo.Bar/*"]} // match all methods in service Defensive patterns
Strategy: validation
Validate before calling
parts := strings.Split(method, "/")
if len(parts) == 2 && parts[1] == "" {
return fmt.Errorf("method name after / must be non-empty; use * for wildcard")
} Type guard
func isValidMethodPattern(m string) bool {
parts := strings.Split(m, "/")
return len(parts) == 2 && parts[1] != ""
} Prevention
- Never leave the method part empty; use * for all methods in a service.
- Fix config templates that append a trailing slash unconditionally.
- Validate patterns before applying the config.
When it happens
Trigger: A method entry in the observability config ends with a trailing slash and no method name, e.g., foo.Bar/. The split produces ["foo.Bar", ""], and the empty second element triggers the error.
Common situations: Developers use a trailing slash intending it as a prefix or directory separator (common in REST-style path thinking), or accidentally leave it after editing. Also from templated config generation that appends '/' unconditionally.
Related errors
- cannot have a leading slash
- cannot have exclude and a '*' wildcard
- / must come in between service and method, only one /
- empty string is not a valid method binary logging config
- grpc: the provided default service config is invalid
AI-assisted analysis of grpc/grpc-go@0c51461d27 (2026-08-11).
Data as JSON: /api/errors/1b80011d4ac27983.
Report an issue: GitHub.
Appendix: source
Thrown at gcp/observability/config.go:68
logger.Infof("Failed to find project ID in default credential: %v", err)
return ""
}
logger.Infof("Found project ID from Google Default Credential: %v", credentials.ProjectID)
return credentials.ProjectID
}
// validateMethodString validates whether the string passed in is a valid
// pattern.
func validateMethodString(method string) error {
if strings.HasPrefix(method, "/") {
return errors.New("cannot have a leading slash")
}
serviceMethod := strings.Split(method, "/")
if len(serviceMethod) != 2 {
return errors.New("/ must come in between service and method, only one /")
}
if serviceMethod[1] == "" {
return errors.New("method name must be non empty")
}
if serviceMethod[0] == "*" {
return errors.New("cannot have service wildcard * i.e. (*/m)")
}
return nil
}
func validateLogEventMethod(methods []string, exclude bool) error {
for _, method := range methods {
if method == "*" {
if exclude {
return errors.New("cannot have exclude and a '*' wildcard")
}
continue
}
if err := validateMethodString(method); err != nil {
return fmt.Errorf("invalid method string: %v, err: %v", method, err)
}View on GitHub (pinned to 0c51461d27)