{"record":{"id":"f6a6851544102f4a","repo":"kubernetes/kops","slug":"could-not-parse-certificate","errorCode":null,"errorMessage":"could not parse certificate","messagePattern":"could not parse certificate","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/pki/certificate.go","lineNumber":100,"sourceCode":"\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}\n\nvar _ io.WriterTo = &Certificate{}\n\nfunc parsePEMCertificate(pemData []byte) (*x509.Certificate, error) {\n\tfor {\n\t\tblock, rest := pem.Decode(pemData)\n\t\tif block == nil {\n\t\t\treturn nil, fmt.Errorf(\"could not parse certificate\")\n\t\t}\n\n\t\tif block.Type == \"CERTIFICATE\" {\n\t\t\tklog.V(10).Infof(\"Parsing pem block: %q\", block.Type)\n\t\t\treturn x509.ParseCertificate(block.Bytes)\n\t\t}\n\t\tklog.Infof(\"Ignoring unexpected PEM block: %q\", block.Type)\n\n\t\tpemData = rest\n\t}\n}\n\nfunc (c *Certificate) AsString() (string, error) {\n\t// Nicer behaviour because this is called from templates\n\tif c == nil {\n\t\treturn \"\", fmt.Errorf(\"AsString called on nil Certificate\")\n\t}\n","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/pki/certificate.go#L82-L118","documentation":"A sentinel error raised by parsePEMCertificate when pem.Decode finds no PEM block at all in the input bytes — the data contains no recognizable BEGIN/END PEM structure, so no certificate can be extracted.","triggerScenarios":"Thrown at pkg/pki/certificate.go:100 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the input is PEM-encoded (-----BEGIN CERTIFICATE----- ... -----END CERTIFICATE-----)","Check for truncation, whitespace stripping, or encoding corruption of the stored certificate","If the data is base64, decode it first (UnmarshalJSON already attempts this fallback)"],"exampleFix":null,"handlingStrategy":"type-guard","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-12T07:17:12.445Z"}