From 3782eb438c3038410d163727b2c047a9259ce394 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Mon, 29 Sep 2025 13:45:08 +0200 Subject: [PATCH] Exceptions: Pass in detailed error messages --- .../src/main/java/pgp/cert_d/PGPCertificateDirectory.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pgp-cert-d-java/src/main/java/pgp/cert_d/PGPCertificateDirectory.java b/pgp-cert-d-java/src/main/java/pgp/cert_d/PGPCertificateDirectory.java index 293f158..dfcdd8a 100644 --- a/pgp-cert-d-java/src/main/java/pgp/cert_d/PGPCertificateDirectory.java +++ b/pgp-cert-d-java/src/main/java/pgp/cert_d/PGPCertificateDirectory.java @@ -48,11 +48,11 @@ public class PGPCertificateDirectory public Certificate getByFingerprint(String fingerprint) throws BadDataException, BadNameException, IOException { if (!openPgpV4FingerprintPattern.matcher(fingerprint).matches() && !openPgpV6FingerprintPattern.matcher(fingerprint).matches()) { - throw new BadNameException(); + throw new BadNameException("Queried fingerprint '" + fingerprint + "' does neither match OpenPGP v4 nor OpenPGP v6 format."); } Certificate certificate = backend.readByFingerprint(fingerprint); if (certificate == null) { - throw new NoSuchElementException(); + throw new NoSuchElementException("No certificate with fingerprint '" + fingerprint + "' found."); } return certificate; } @@ -74,7 +74,7 @@ public class PGPCertificateDirectory if (keyMaterial != null) { return keyMaterial.asCertificate(); } - throw new NoSuchElementException(); + throw new NoSuchElementException("No certificate with special name '" + specialName + "' found."); } @Override @@ -131,7 +131,7 @@ public class PGPCertificateDirectory try { KeyMaterial keyMaterial = backend.readBySpecialName(SpecialNames.TRUST_ROOT); if (keyMaterial == null) { - throw new NoSuchElementException(); + throw new NoSuchElementException("No trust-root found."); } return keyMaterial; } catch (BadNameException e) {