grpc/grpc-go · error

/ must come in between service and method, only one /

Error message

/ must come in between service and method, only one /

What it means

Returned by validateMethodString when the method pattern does not contain exactly one '/' separator between the service name and method name. The function splits the string by '/' and requires exactly two parts. Zero slashes (e.g., fooBar) or multiple slashes (e.g., a/b/c) both trigger this error.

Solutions

  1. Ensure each method pattern has exactly one '/' separating the fully-qualified service name from the method name: pkg.Service/Method.
  2. Use the '*' wildcard for the method part (pkg.Service/*) to match all methods in a service.

Example fix

// before
{"methods":["foo.Bar.Baz"]} // no slash → error
// after
{"methods":["foo.Bar/Baz"]} // service/method
Defensive patterns

Strategy: validation

Validate before calling

parts := strings.Split(method, "/")
if len(parts) != 2 {
    return fmt.Errorf("method must be service/method with exactly one /, got %d parts", len(parts))
}

Type guard

func isValidMethodPattern(m string) bool {
    parts := strings.Split(m, "/")
    return len(parts) == 2 && parts[0] != "" && parts[1] != ""
}

Prevention

When it happens

Trigger: A method entry in the observability logging config has no slash (e.g., Foo) or more than one slash (e.g., pkg/Foo/Bar). The pattern must be exactly service/method.

Common situations: Developers enter a bare service name without a method, or a fully-qualified path with extra segments. Misunderstanding the expected format as a URL-like path with multiple segments.

Related errors


AI-assisted analysis of grpc/grpc-go@0c51461d27 (2026-08-11). Data as JSON: /api/errors/0f8e94d1202a05b4. Report an issue: GitHub.

Appendix: source

Thrown at gcp/observability/config.go:65

		return ""
	}
	if credentials.ProjectID == "" {
		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
		}

View on GitHub (pinned to 0c51461d27)