{"record":{"id":"522d6da6b30e0d4a","repo":"grafana/k6","slug":"failed-to-append-certificate-from-pem-w","errorCode":null,"errorMessage":"failed to append certificate from PEM: %w","messagePattern":"failed to append certificate from PEM: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/grpc/client.go","lineNumber":176,"sourceCode":"\t\t\t}\n\t\t}\n\t}\n\n\t// Ignoring 'TLS MinVersion is too low' because this tls.Config will inherit MinValue and MaxValue\n\t// from the vu state tls.Config\n\n\ttlsCfg := &tls.Config{\n\t\tCipherSuites:       parentConfig.CipherSuites,\n\t\tInsecureSkipVerify: parentConfig.InsecureSkipVerify, //nolint:gosec\n\t\tMinVersion:         parentConfig.MinVersion,\n\t\tMaxVersion:         parentConfig.MaxVersion,\n\t\tRenegotiation:      parentConfig.Renegotiation,\n\t\tRootCAs:            cp,\n\t}\n\tif len(certificate) > 0 && len(key) > 0 {\n\t\tcert, err := tls.X509KeyPair(certificate, key)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to append certificate from PEM: %w\", err)\n\t\t}\n\t\ttlsCfg.Certificates = []tls.Certificate{cert}\n\t}\n\treturn tlsCfg, nil\n}\n\nfunc buildTLSConfigFromMap(parentConfig *tls.Config, tlsConfigMap map[string]any) (*tls.Config, error) {\n\tvar cert, key, pass []byte\n\tvar ca [][]byte\n\tvar err error\n\tif certstr, ok := tlsConfigMap[\"cert\"].(string); ok {\n\t\tcert = []byte(certstr)\n\t}\n\tif keystr, ok := tlsConfigMap[\"key\"].(string); ok {\n\t\tkey = []byte(keystr)\n\t}\n\tif passwordStr, ok := tlsConfigMap[\"password\"].(string); ok {\n\t\tpass = []byte(passwordStr)","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/js/modules/k6/grpc/client.go#L158-L194","documentation":"Raised in buildTLSConfig when tls.X509KeyPair fails to load the client certificate and key PEM pair supplied in the grpc.connect tls options — mismatched cert/key, malformed PEM, or encrypted key issues.","triggerScenarios":"Thrown at internal/js/modules/k6/grpc/client.go:176 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure the certificate and key PEM match each other (same key pair)","Check both blobs are complete, valid PEM encodings","If the key is encrypted, decrypt it first since the raw pair loader is used here"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}