{"record":{"id":"11525f3b3238d7cf","repo":"kubernetes/kops","slug":"asbytes-called-on-nil-certificate","errorCode":null,"errorMessage":"AsBytes called on nil Certificate","messagePattern":"AsBytes called on nil Certificate","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/pki/certificate.go","lineNumber":130,"sourceCode":"\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\n\tvar data bytes.Buffer\n\t_, err := c.WriteTo(&data)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"error writing SSL certificate: %v\", err)\n\t}\n\treturn data.String(), nil\n}\n\nfunc (c *Certificate) AsBytes() ([]byte, error) {\n\t// Nicer behaviour because this is called from templates\n\tif c == nil {\n\t\treturn nil, fmt.Errorf(\"AsBytes called on nil Certificate\")\n\t}\n\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 data.Bytes(), nil\n}\n\nfunc (c *Certificate) WriteTo(w io.Writer) (int64, error) {\n\t// For the dry-run case\n\tif c.Certificate == nil {\n\t\treturn 0, nil\n\t}\n\n\tvar b bytes.Buffer\n\terr := pem.Encode(&b, &pem.Block{Type: \"CERTIFICATE\", Bytes: c.Certificate.Raw})","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/pki/certificate.go#L112-L148","documentation":"Same nil-receiver guard as AsString but for Certificate.AsBytes: when a template renders a certificate as bytes and the Certificate pointer is nil, this sentinel fires. It indicates the referenced certificate was not issued/loaded before rendering, and prevents a panic inside template execution.","triggerScenarios":"Thrown at pkg/pki/certificate.go:130 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure the certificate is populated before code/templates call AsBytes","Trace why the Certificate pointer is nil (load or issuance failure)","Handle missing certificates explicitly in template rendering"],"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"}