grpc-ecosystem/grpc-gateway · error

invalid character %q(%U) in identifier: %s

Error message

invalid character %q(%U) in identifier: %s

What it means

Identifier-validation error from expectIdent: the token contains a character outside [A-Za-z0-9_] (and does not merely start with a digit). accept(typeIdent) rejects it, so the faulting input is a malformed identifier — e.g. containing '-', '.', or spaces — in the HttpRule path template.

Source

Thrown at internal/httprule/parse.go:352

func expectIdent(ident string) error {
	if ident == "" {
		return errors.New("empty identifier")
	}
	for pos, r := range ident {
		switch {
		case '0' <= r && r <= '9':
			if pos == 0 {
				return fmt.Errorf("identifier starting with digit: %s", ident)
			}
			continue
		case 'A' <= r && r <= 'Z':
			continue
		case 'a' <= r && r <= 'z':
			continue
		case r == '_':
			continue
		default:
			return fmt.Errorf("invalid character %q(%U) in identifier: %s", r, r, ident)
		}
	}
	return nil
}

func isHexDigit(r rune) bool {
	switch {
	case '0' <= r && r <= '9':
		return true
	case 'A' <= r && r <= 'F':
		return true
	case 'a' <= r && r <= 'f':
		return true
	}
	return false
}

View on GitHub (pinned to a58a4436a3)

Solutions

  1. Replace invalid characters with letters, digits or underscores in the identifier.
  2. Ensure field-path components use the actual proto field names without decoration.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at internal/httprule/parse.go:352 when the library encounters an invalid state.

Common situations: See trigger scenarios.

Understand the failure class


AI-assisted analysis of grpc-ecosystem/grpc-gateway@a58a4436a3 (2026-09-02). Data as JSON: /api/errors/c0ecbffb676be804. Report an issue: GitHub.