grafana/k6 · error

invalid tls cert value: '%#v', it needs to be a PEM…

Error message

invalid tls cert value: '%#v', it needs to be a PEM formatted string

What it means

Raised by parseConnectTLSParam when the optional `cert` entry inside the tls object of grpc.Client.connect() params exists but is not a string. The parser only accepts the certificate as a PEM-formatted string; any other type fails the type assertion. Note the error echoes the whole tls value (v), not just the cert entry.

Solutions

  1. Provide the client certificate as a PEM string, e.g. tls: { cert: open('cert.pem') } using k6's open() which returns the file contents
  2. Do not pass a binary ArrayBuffer or parsed certificate object as cert
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at internal/js/modules/k6/grpc/params.go:230 when the library encounters an invalid state.

Common situations: See trigger scenarios.

Understand the failure class


AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18). Data as JSON: /api/errors/9cd0dd5c5b42869f. Report an issue: GitHub.

Appendix: source

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

		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 {
		if _, ok = cert.(string); !ok {
			return fmt.Errorf("invalid tls cert value: '%#v', it needs to be a PEM formatted string", v)
		}
	}
	if key, keyok := params.TLS["key"]; keyok {
		if _, ok = key.(string); !ok {
			return fmt.Errorf("invalid tls key value: '%#v', it needs to be a PEM formatted string", v)
		}
	}
	if pass, passok := params.TLS["password"]; passok {
		if _, ok = pass.(string); !ok {
			return fmt.Errorf("invalid tls password value: '%#v', it needs to be a string", v)
		}
	}
	if cacerts, cacertsok := params.TLS["cacerts"]; cacertsok {
		var cacertsArray []any
		if cacertsArray, ok = cacerts.([]any); ok {
			for _, cacertsArrayEntry := range cacertsArray {
				if _, ok = cacertsArrayEntry.(string); !ok {
					return fmt.Errorf("invalid tls cacerts value: '%#v',"+

View on GitHub (pinned to 01ffac6f24)