{"record":{"id":"d5d1570d06b2a61e","repo":"kubernetes/kops","slug":"error-writing-ssl-certificate-v","errorCode":null,"errorMessage":"error writing SSL certificate: %v","messagePattern":"error writing SSL certificate: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/pki/certificate.go","lineNumber":74,"sourceCode":"\t\t\t\t}\n\t\t\t}\n\n\t\t\tif err != nil {\n\t\t\t\tklog.Infof(\"Invalid certificate data: %q\", string(b))\n\t\t\t\treturn fmt.Errorf(\"error parsing certificate: %v\", err)\n\t\t\t}\n\t\t}\n\t\t*c = *r\n\t\treturn nil\n\t}\n\treturn fmt.Errorf(\"unknown format for Certificate: %q\", string(b))\n}\n\nfunc (c *Certificate) MarshalJSON() ([]byte, error) {\n\tvar data bytes.Buffer\n\t_, err := c.WriteTo(&data)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error writing SSL certificate: %v\", err)\n\t}\n\treturn json.Marshal(data.String())\n}\n\nfunc ParsePEMCertificate(pemData []byte) (*Certificate, error) {\n\tcert, err := parsePEMCertificate(pemData)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tc := &Certificate{\n\t\tSubject:     cert.Subject,\n\t\tCertificate: cert,\n\t\tPublicKey:   cert.PublicKey,\n\t\tIsCA:        cert.IsCA,\n\t}\n\treturn c, nil\n}","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/pki/certificate.go#L56-L92","documentation":"Fires in Certificate.MarshalJSON when Certificate.WriteTo fails while serializing the certificate to PEM into a buffer before JSON encoding — typically because the underlying x509 certificate data cannot be encoded.","triggerScenarios":"Thrown at pkg/pki/certificate.go:74 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the wrapped %v error to find the underlying WriteTo failure","Ensure the Certificate was successfully parsed/issued and is not internally corrupt","Re-issue the certificate if its stored x509 data is invalid"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}