grafana/k6 · error

invalid authority value: '%#v', it needs to be a string

Error message

invalid authority value: '%#v', it needs to be a string

What it means

The authority option in client.connect() overrides the HTTP/2 :authority pseudo-header (virtual host) for the connection and must be a string (params.go:208). Numbers, booleans or objects throw 'invalid authority value ... needs to be a string'.

Source

Thrown at internal/js/modules/k6/grpc/params.go:210

			}
		case "maxSendSize":
			var ok bool
			result.MaxSendSize, ok = v.(int64)
			if !ok {
				return result, fmt.Errorf("invalid maxSendSize value: '%#v', it needs to be an integer", v)
			}
			if result.MaxSendSize < 0 {
				return result, fmt.Errorf("invalid maxSendSize value: '%#v, it needs to be a positive integer", v)
			}
		case "tls":
			if err := parseConnectTLSParam(result, v); err != nil {
				return result, err
			}
		case "authority":
			var ok bool
			result.Authority, ok = v.(string)
			if !ok {
				return result, fmt.Errorf("invalid authority value: '%#v', it needs to be a string", v)
			}
		default:
			return result, fmt.Errorf("unknown connect param: %q", k)
		}
	}

	return result, nil
}

func parseConnectTLSParam(params *connectParams, v any) error {
	var ok bool
	params.TLS, ok = v.(map[string]any)

	if !ok {
		return fmt.Errorf("invalid tls value: '%#v', expected (optional) keys: cert, key, password, and cacerts", v)
	}
	// optional map keys below
	if cert, certok := params.TLS["cert"]; certok {

View on GitHub (pinned to 93accf6570)

Solutions

  1. Pass a hostname string: authority: 'api.example.com'
  2. Stringify non-string config values: String(host)
  3. Keep the port in the address argument, not in authority

Example fix

// before
client.connect('localhost:8080', { authority: 8080 });

// after
client.connect('localhost:8080', { authority: 'api.example.com' });
Defensive patterns

Strategy: validation

Validate before calling

if (connectParams.authority !== undefined && typeof connectParams.authority !== 'string') {
  throw new Error(`authority must be a string, got ${typeof connectParams.authority}`);
}
client.connect(addr, connectParams);

Type guard

function isAuthority(v) {
  return v == null || typeof v === 'string';
}

Prevention

When it happens

Trigger: connect(addr, { authority: 8080 }); { authority: true }; authority taken from untyped config such as a port or numeric ID field.

Common situations: Routing through proxies or load balancers that require a specific :authority; mixing up the port (belongs in the address argument) and the authority field in config.

Related errors


AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15). Data as JSON: /api/errors/0355d386f8f3f573. Report an issue: GitHub.