grafana/k6 · error
invalid tls key value: '%#v', it needs to be a PEM…
Error message
invalid tls key value: '%#v', it needs to be a PEM formatted string
What it means
Raised by parseConnectTLSParam when the optional `key` entry inside the tls object of grpc.Client.connect() params exists but is not a string. The private key must be supplied as a PEM-formatted string; the type assertion on string fails for any other JS value.
Solutions
- Provide the private key as a PEM string loaded via open('key.pem')
- Ensure the key is not wrapped in an array or object
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at internal/js/modules/k6/grpc/params.go:235 when the library encounters an invalid state.
Common situations: See trigger scenarios.
Understand the failure class
- SSL/TLS and certificate errors — how TLS handshakes and certificate validation fail.
AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18).
Data as JSON: /api/errors/1fae4c7b9cfda6a3.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/grpc/params.go:235
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',"+
" it needs to be a string or an array of PEM formatted strings", v)
}
}
} else if _, ok = cacerts.(string); !ok {
return fmt.Errorf("invalid tls cacerts value: '%#v',"+View on GitHub (pinned to 01ffac6f24)