grafana/k6 · error

invalid tls value: '%#v', expected (optional) keys: cert…

Error message

invalid tls value: '%#v', expected (optional) keys: cert, key, password, and cacerts

What it means

Raised by parseConnectTLSParam when the `tls` key of the connect params object passed to grpc.Client.connect() is not a JavaScript object. The function type-asserts the value to map[string]any before looking for the optional cert/key/password/cacerts keys; any other JS type (string, number, array, null) fails the assertion and produces this error. The offending value is echoed with %#v.

Solutions

  1. Pass an object literal for tls, e.g. client.connect(url, { tls: { cacerts: [pem] } })
  2. Omit the tls key entirely if no custom TLS settings are needed
  3. Ensure you are not accidentally passing a JSON string instead of a parsed object
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at internal/js/modules/k6/grpc/params.go:225 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/f04f5fc5343a45ab. Report an issue: GitHub.

Appendix: source

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

			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 {
		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 {

View on GitHub (pinned to 01ffac6f24)