grpc-ecosystem/grpc-gateway · error

unterminated variable segment: %s

Error message

unterminated variable segment: %s

What it means

Parser error from parser.variable: the closing '}' of a variable segment was not found where expected, i.e. the HttpRule path template opens '{name' but never closes it. The error names the variable path so the unclosed brace can be located.

Source

Thrown at internal/httprule/parse.go:202

	}

	path, err := p.fieldPath()
	if err != nil {
		return nil, err
	}

	var segs []segment
	if _, err := p.accept("="); err == nil {
		segs, err = p.segments()
		if err != nil {
			return nil, fmt.Errorf("invalid segment in variable %q: %w", path, err)
		}
	} else {
		segs = []segment{wildcard{}}
	}

	if _, err := p.accept("}"); err != nil {
		return nil, fmt.Errorf("unterminated variable segment: %s", path)
	}
	return variable{
		path:     path,
		segments: segs,
	}, nil
}

func (p *parser) fieldPath() (string, error) {
	c, err := p.accept(typeIdent)
	if err != nil {
		return "", err
	}
	components := []string{c}
	for {
		if _, err := p.accept("."); err != nil {
			return strings.Join(components, "."), nil
		}
		c, err := p.accept(typeIdent)

View on GitHub (pinned to a58a4436a3)

Solutions

  1. Add the missing '}' to close the variable in the path template.
  2. Check that wildcard patterns inside the variable did not swallow the closing brace.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at internal/httprule/parse.go:202 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/207715bc5e4a8f91. Report an issue: GitHub.