{"id":"97d6d442292d7cf1","repo":"jackc/pgx","slug":"unable-to-load-cert-w","errorCode":null,"errorMessage":"unable to load cert: %w","messagePattern":"unable to load cert: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pgconn/config.go","lineNumber":974,"sourceCode":"\t\t\tif decryptedError != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"unable to decrypt key: %w\", decryptedError)\n\t\t\t}\n\n\t\t\tpemBytes := pem.Block{\n\t\t\t\tType:  \"RSA PRIVATE KEY\",\n\t\t\t\tBytes: decryptedKey,\n\t\t\t}\n\t\t\tpemKey = pem.EncodeToMemory(&pemBytes)\n\t\t} else {\n\t\t\tpemKey = pem.EncodeToMemory(block)\n\t\t}\n\t\tcertfile, err := os.ReadFile(sslcert)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"unable to read cert: %w\", err)\n\t\t}\n\t\tcert, err := tls.X509KeyPair(certfile, pemKey)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"unable to load cert: %w\", err)\n\t\t}\n\t\ttlsConfig.Certificates = []tls.Certificate{cert}\n\t}\n\n\t// Set Server Name Indication (SNI), if enabled by connection parameters.\n\t// Per RFC 6066, do not set it if the host is a literal IP address (IPv4\n\t// or IPv6).\n\tif sslsni == \"1\" && net.ParseIP(host) == nil {\n\t\ttlsConfig.ServerName = host\n\t}\n\n\tswitch sslmode {\n\tcase \"allow\":\n\t\treturn []*tls.Config{nil, tlsConfig}, nil\n\tcase \"prefer\":\n\t\treturn []*tls.Config{tlsConfig, nil}, nil\n\tcase \"require\", \"verify-ca\", \"verify-full\":\n\t\treturn []*tls.Config{tlsConfig}, nil","sourceCodeStart":956,"sourceCodeEnd":992,"githubUrl":"https://github.com/jackc/pgx/blob/ec1a0befd22592cffffdeeb0a50311b506372f4c/pgconn/config.go#L956-L992","documentation":"Error \"unable to load cert: %w\" thrown in jackc/pgx.","triggerScenarios":"Thrown at pgconn/config.go:974 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"analyzedSha":"ec1a0befd22592cffffdeeb0a50311b506372f4c","analyzedAt":"2026-08-04T22:52:11.263Z","schemaVersion":2}