grafana/k6 · error

invalid plaintext value: '%#v', it needs to be boolean

Error message

invalid plaintext value: '%#v', it needs to be boolean

What it means

In client.connect(addr, params), the plaintext option toggles plaintext HTTP/2 (h2c) instead of TLS and must be a JS boolean; newConnectParams asserts the type (params.go:161). 'false' as a string, 0/1 numbers, or any other type throw 'invalid plaintext value'.

Source

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

		ReflectionMetadata:    metadata.New(nil),
	}

	if common.IsNullish(input) {
		return result, nil
	}

	rt := vu.Runtime()
	params := input.ToObject(rt)

	for _, k := range params.Keys() {
		v := params.Get(k).Export()

		switch k {
		case "plaintext":
			var ok bool
			result.IsPlaintext, ok = v.(bool)
			if !ok {
				return result, fmt.Errorf("invalid plaintext value: '%#v', it needs to be boolean", v)
			}
		case "timeout":
			var err error
			result.Timeout, err = types.GetDurationValue(v)
			if err != nil {
				return result, fmt.Errorf("invalid timeout value: %w", err)
			}
		case "reflect":
			var ok bool
			result.UseReflectionProtocol, ok = v.(bool)
			if !ok {
				return result, fmt.Errorf("invalid reflect value: '%#v', it needs to be boolean", v)
			}
		case "reflectMetadata":
			md, err := newMetadata(params.Get(k))
			if err != nil {
				return result, fmt.Errorf("invalid reflectMetadata param: %w", err)
			}

View on GitHub (pinned to 93accf6570)

Solutions

  1. Use a literal true/false
  2. Coerce env values explicitly: __ENV.GRPC_PLAINTEXT === 'true'
  3. Fix the config loader to emit real booleans

Example fix

// before
client.connect(addr, { plaintext: __ENV.GRPC_PLAINTEXT });

// after
client.connect(addr, { plaintext: __ENV.GRPC_PLAINTEXT === 'true' });
Defensive patterns

Strategy: validation

Validate before calling

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

Type guard

function toBool(v) {
  if (typeof v === 'boolean') return v;
  if (typeof v === 'string') return v === 'true';
  throw new Error(`expected boolean, got ${typeof v}`);
}

Prevention

When it happens

Trigger: connect(addr, { plaintext: 'false' }); { plaintext: 1 }; values taken straight from __ENV, which always yields strings.

Common situations: Env-driven TLS toggles (__ENV.GRPC_PLAINTEXT); YAML/JSON config loaded without type coercion; assuming 0/1 work as in other tools.

Related errors


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