caddyserver/caddy · error

failed to parse root certificate

Error message

failed to parse root certificate: %v

What it means

rootCertFromAdmin wraps x509.ParseCertificate failing on the DER bytes of the decoded PEM block: the bytes are well-formed PEM but do not parse as a valid X.509 certificate, so the root cert for the CA cannot be returned to cmdTrust/cmdUntrust.

Solutions

  1. Ensure the root certificate is a valid X.509 certificate; re-fetch it from the CA if corrupted.
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at modules/caddypki/command.go:231 when the library encounters an invalid state.

Common situations: See trigger scenarios.

Understand the failure class


AI-assisted analysis of caddyserver/caddy@50e54ee279 (2026-08-15). Data as JSON: /api/errors/95b36582494c90ba. Report an issue: GitHub.

Appendix: source

Thrown at modules/caddypki/command.go:231

		return nil, fmt.Errorf("requesting CA info: %v", err)
	}
	defer resp.Body.Close()

	// Decode the response
	caInfo := new(caInfo)
	err = json.NewDecoder(resp.Body).Decode(caInfo)
	if err != nil {
		return nil, fmt.Errorf("failed to decode JSON response: %v", err)
	}

	// Decode the root cert
	rootBlock, _ := pem.Decode([]byte(caInfo.RootCert))
	if rootBlock == nil {
		return nil, fmt.Errorf("failed to decode root certificate: %v", err)
	}
	rootCert, err := x509.ParseCertificate(rootBlock.Bytes)
	if err != nil {
		return nil, fmt.Errorf("failed to parse root certificate: %v", err)
	}

	return rootCert, nil
}

View on GitHub (pinned to 50e54ee279)