grpc/grpc-go · error

method name must be non empty

Error message

method name must be non empty

What it means

Returned by validateMethodString (gcp/observability/config.go:68) when, after splitting on '/', the method part (serviceMethod[1]) is empty. This is the trailing-slash case: the split produced exactly two parts and the service was given but the method is empty (e.g. 'foo.Bar/'). Note the order: this check runs after the slash-count check (line 64) passes, so it only fires for the single-slash-but-empty-method shape.

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 03255a9237)

Solutions

  1. Provide a non-empty method name after the slash (foo.Bar/Baz).
  2. If building entries programmatically, skip/guard against empty method values.
  3. Review the rendered config for entries ending in '/'.

Example fix

// before
{"methods":["foo.Bar/"]}

// after
{"methods":["foo.Bar/Baz"]}
Defensive patterns

Strategy: validation

Validate before calling

parts := strings.Split(method, "/")
if len(parts) == 2 && parts[1] == "" {
    return fmt.Errorf("method %q: trailing slash with empty method name", method)
}

Try / catch

if _, err := unmarshalAndVerifyConfig(raw); err != nil { log.Fatal(err) }

Prevention

When it happens

Trigger: A methods entry ending in '/' with nothing after it (foo.Bar/), or constructed by string concatenation where the method portion was empty.

Common situations: Trailing slash typo; building the string via fmt.Sprintf("%s/%s", svc, method) where method is empty; truncation when editing config.

Related errors


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