grpc-ecosystem/grpc-gateway · error

unknown termType %q

Error message

unknown termType %q

What it means

Internal parser error from parser.accept: it was invoked with a termType outside its known set (literal separators, EOF, ident, literal). This indicates a bug in the httprule grammar wiring rather than user input; accept cannot classify the terminal and refuses to proceed.

Source

Thrown at internal/httprule/parse.go:267

	switch term {
	case "/", "*", "**", ".", "=", "{", "}":
		if t != string(term) && t != "/" {
			return "", fmt.Errorf("expected %q but got %q", term, t)
		}
	case typeEOF:
		if t != eof {
			return "", fmt.Errorf("expected EOF but got %q", t)
		}
	case typeIdent:
		if err := expectIdent(t); err != nil {
			return "", err
		}
	case typeLiteral:
		if err := expectPChars(t); err != nil {
			return "", err
		}
	default:
		return "", fmt.Errorf("unknown termType %q", term)
	}
	p.tokens = p.tokens[1:]
	p.accepted = append(p.accepted, t)
	return t, nil
}

// expectPChars determines if "t" consists of only pchars defined in RFC3986.
//
// https://www.ietf.org/rfc/rfc3986.txt, P.49
//
//	pchar         = unreserved / pct-encoded / sub-delims / ":" / "@"
//	unreserved    = ALPHA / DIGIT / "-" / "." / "_" / "~"
//	sub-delims    = "!" / "$" / "&" / "'" / "(" / ")"
//	              / "*" / "+" / "," / ";" / "="
//	pct-encoded   = "%" HEXDIG HEXDIG
func expectPChars(t string) error {
	const (
		init = iota

View on GitHub (pinned to a58a4436a3)

Solutions

  1. Report/fix the parser bug: only the defined termTypes (separators, $, ident, literal) may be passed to accept.
  2. Verify no custom modification introduced a new terminal without a case in accept.
Defensive patterns

Strategy: fallback

When it happens

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

Common situations: See trigger scenarios.


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