Exceptions: Pass in detailed error messages

This commit is contained in:
Paul Schaub 2025-09-29 13:45:08 +02:00
parent b9083c4394
commit 3782eb438c
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -48,11 +48,11 @@ public class PGPCertificateDirectory
public Certificate getByFingerprint(String fingerprint) throws BadDataException, BadNameException, IOException { public Certificate getByFingerprint(String fingerprint) throws BadDataException, BadNameException, IOException {
if (!openPgpV4FingerprintPattern.matcher(fingerprint).matches() && if (!openPgpV4FingerprintPattern.matcher(fingerprint).matches() &&
!openPgpV6FingerprintPattern.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); Certificate certificate = backend.readByFingerprint(fingerprint);
if (certificate == null) { if (certificate == null) {
throw new NoSuchElementException(); throw new NoSuchElementException("No certificate with fingerprint '" + fingerprint + "' found.");
} }
return certificate; return certificate;
} }
@ -74,7 +74,7 @@ public class PGPCertificateDirectory
if (keyMaterial != null) { if (keyMaterial != null) {
return keyMaterial.asCertificate(); return keyMaterial.asCertificate();
} }
throw new NoSuchElementException(); throw new NoSuchElementException("No certificate with special name '" + specialName + "' found.");
} }
@Override @Override
@ -131,7 +131,7 @@ public class PGPCertificateDirectory
try { try {
KeyMaterial keyMaterial = backend.readBySpecialName(SpecialNames.TRUST_ROOT); KeyMaterial keyMaterial = backend.readBySpecialName(SpecialNames.TRUST_ROOT);
if (keyMaterial == null) { if (keyMaterial == null) {
throw new NoSuchElementException(); throw new NoSuchElementException("No trust-root found.");
} }
return keyMaterial; return keyMaterial;
} catch (BadNameException e) { } catch (BadNameException e) {