From 76a4ef50cb593ef9fed8dc981e6804ed3e58dda1 Mon Sep 17 00:00:00 2001 From: Jan-Peter Klein Date: Tue, 11 Feb 2025 16:21:53 +0100 Subject: [PATCH] improve exception handling --- .../common/vaults/VaultListManager.java | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/cryptomator/common/vaults/VaultListManager.java b/src/main/java/org/cryptomator/common/vaults/VaultListManager.java index 2e9173a22..c8c37893e 100644 --- a/src/main/java/org/cryptomator/common/vaults/VaultListManager.java +++ b/src/main/java/org/cryptomator/common/vaults/VaultListManager.java @@ -50,9 +50,9 @@ public class VaultListManager { @Inject public VaultListManager(ObservableList vaultList, // AutoLocker autoLocker, // - List mountServices, - VaultComponent.Factory vaultComponentFactory, - ResourceBundle resourceBundle, + List mountServices, // + VaultComponent.Factory vaultComponentFactory, // + ResourceBundle resourceBundle, // Settings settings) { this.vaultList = vaultList; this.autoLocker = autoLocker; @@ -71,17 +71,15 @@ public class VaultListManager { throw new NoSuchFileException(normalizedPathToVault.toString(), null, "Not a vault directory"); } - return get(normalizedPathToVault) // - .orElseGet(() -> { - Vault newVault = create(newVaultSettings(normalizedPathToVault)); - try { - setVaultScheme(newVault); - } catch (IOException e) { - throw new RuntimeException(e); - } - vaultList.add(newVault); - return newVault; - }); + var maybeVault = get(normalizedPathToVault); + if (maybeVault.isEmpty()) { + Vault newVault = create(newVaultSettings(normalizedPathToVault)); + setVaultScheme(newVault); + vaultList.add(newVault); + return newVault; + } else { + return maybeVault.get(); + } } private void setVaultScheme(Vault vault) throws IOException { @@ -94,11 +92,11 @@ public class VaultListManager { } } catch (NoSuchFileException e) { vault.stateProperty().set(VaultState.Value.ERROR); - LOG.error("Configuration file missing or corrupted.", e); + LOG.error("Configuration file missing.", e); } catch (IOException e) { vault.stateProperty().set(VaultState.Value.ERROR); LOG.error("Unexpected IO exception while setting vault scheme.", e); - throw new IOException("Configuration file missing or corrupted.", e); + throw e; } }