grpc/grpc-go · error

invalid method string: %v, err: %v

Error message

invalid method string: %v, err: %v

What it means

validateLogEventMethod iterates the Methods list of a CloudLogging RPC event config and runs validateMethodString on each entry (other than the lone "*"). A method fails validation if it has a leading slash, does not contain exactly one '/' separator, has an empty method name, or uses '*' as the service name. The format required is `<fullyQualifiedService>/<method>`.

Source

Thrown at gcp/observability/config.go:85

	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)
		}
	}
	return nil
}

func validateLoggingEvents(config *config) error {
	if config.CloudLogging == nil {
		return nil
	}
	for _, clientRPCEvent := range config.CloudLogging.ClientRPCEvents {
		if err := validateLogEventMethod(clientRPCEvent.Methods, clientRPCEvent.Exclude); err != nil {
			return fmt.Errorf("error in clientRPCEvent method: %v", err)
		}
	}
	for _, serverRPCEvent := range config.CloudLogging.ServerRPCEvents {
		if err := validateLogEventMethod(serverRPCEvent.Methods, serverRPCEvent.Exclude); err != nil {
			return fmt.Errorf("error in serverRPCEvent method: %v", err)
		}

View on GitHub (pinned to 03255a9237)

Solutions

  1. Format each method as <package>.<Service>/<Method> with no leading slash, e.g. "goo.Foo/Bar".
  2. Use "<service>/*" to match all methods of a service, or "*" alone to match everything.
  3. Do not put '*' in the service position; spell out the fully-qualified service name including the package.

Example fix

// before
{ "client_rpc_events": [{ "methods": ["/goo.Foo/Bar"] }] }

// after
{ "client_rpc_events": [{ "methods": ["goo.Foo/Bar"] }] }
Defensive patterns

Strategy: validation

Validate before calling

import "strings"

func validateMethodString(method string) error {
    if strings.HasPrefix(method, "/") { return errors.New("leading slash") }
    parts := strings.Split(method, "/")
    if len(parts) != 2 { return errors.New("exactly one '/' separator") }
    if parts[1] == "" { return errors.New("empty method") }
    if parts[0] == "*" { return errors.New("service wildcard") }
    return nil
}

Try / catch

if err := validateLogEventMethod(methods, exclude); err != nil {
    return fmt.Errorf("method pattern: %w", err)
}

Prevention

When it happens

Trigger: Configuring GRPC_GCP_OBSERVABILITY_CONFIG with method patterns like "/pkg.Svc/Foo" (leading slash), "pkg.Svc.Foo" (no slash), "pkg.Svc/" (empty method), "*/Foo" (service wildcard), or "pkg.Svc/Foo/Bar" (two slashes).

Common situations: Using the gRPC wire-format path (with leading /) instead of the config format; copying a method string from grpcurl output that includes the slash; thinking glob patterns like */Method are allowed.

Related errors


AI-assisted analysis of grpc/grpc-go@03255a9237 (2026-08-07). Data as JSON: /api/errors/d23b19de3c2500f0. Report an issue: GitHub.