err instead of panic
@@ -20,6 +20,7 @@ import (
"crypto/x509"
"crypto/x509/pkix"
"encoding/pem"
+ "fmt"
cmv1alpha2 "github.com/jetstack/cert-manager/pkg/apis/certmanager/v1alpha2"
cmmeta "github.com/jetstack/cert-manager/pkg/apis/meta/v1"
corev1alpha1 "github.com/kapp-staging/kapp/controller/api/v1alpha1"
@@ -261,8 +262,9 @@ func transCertCondition(cond cmv1alpha2.CertificateCondition) corev1alpha1.Https
func ParseCert(certPEM string) (*x509.Certificate, error) {
block, _ := pem.Decode([]byte(certPEM))
if block == nil {
- panic("failed to parse certificate PEM")
+ return nil, fmt.Errorf("failed to parse certificate PEM")
}
+
cert, err := x509.ParseCertificate(block.Bytes)
if err != nil {
return nil, err
