Skip to content

Commit 0aea086

Browse files
committed
Improve error messages
1 parent c9f2b18 commit 0aea086

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/main/java/org/purejava/integrations/keychain/KeePassXCAccess.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,43 +28,41 @@ public KeePassXCAccess() {
2828
@Override
2929
public boolean isLocked() { return proxy.getDatabasehash().isEmpty(); }
3030

31-
@Override
32-
public boolean needsAssociation() { return !proxy.connectionAvailable(); }
31+
private boolean needsAssociation() { return !proxy.connectionAvailable(); }
3332

34-
@Override
35-
public boolean associate() { return proxy.associate(); }
33+
private boolean associate() { return proxy.associate(); }
3634

3735
public String unlock() { return proxy.getDatabasehash(true); }
3836

3937
@Override
4038
public void storePassphrase(String vault, CharSequence password) throws KeychainAccessException {
4139
vault = URL_SCHEME + vault;
4240
if (isLocked()) {
43-
throw new KeychainAccessException("Storing of the passphrase failed");
41+
throw new KeychainAccessException("Failed to store password. KeePassXC database is locked. Needs to be unlocked first");
4442
}
4543
if (!proxy.loginExists(vault, null, false, List.of(proxy.exportConnection()), password.toString())
4644
&& !proxy.setLogin(vault, null, null, "Vault", password.toString(), "default", "default", "default")) {
47-
throw new KeychainAccessException("Storing of the passphrase failed");
45+
throw new KeychainAccessException("Storing of the password failed");
4846
}
4947
}
5048

5149
@Override
5250
public char[] loadPassphrase(String vault) throws KeychainAccessException {
5351
if (isLocked()) {
54-
throw new KeychainAccessException("Loading of the passphrase failed");
52+
throw new KeychainAccessException("Failed to load password. KeePassXC database is locked. Needs to be unlocked first");
5553
}
5654
vault = URL_SCHEME + vault;
5755
var answer = proxy.getLogins(vault, null, false, List.of(proxy.exportConnection()));
5856
if (answer.isEmpty() || null == answer.get("entries")) {
59-
throw new KeychainAccessException("Loading of the passphrase failed");
57+
throw new KeychainAccessException("No password found for vault " + vault);
6058
}
6159
var array = (ArrayList<Object>) answer.get("entries");
6260
var credentials = (HashMap<String, Object>) array.get(0);
6361
if (credentials.get("password") != null) {
6462
var password = (String) credentials.get("password");
6563
return password.toCharArray();
6664
} else {
67-
throw new KeychainAccessException("Loading of the passphrase failed");
65+
throw new KeychainAccessException("Loading of the password failed");
6866
}
6967
}
7068

0 commit comments

Comments
 (0)