Browse Source

Updated Errorhandling of UnlockWorkflow

JaniruTEC 4 năm trước cách đây
mục cha
commit
6aa14fcfb1

+ 0 - 4
main/commons/src/main/java/org/cryptomator/common/vaults/Vault.java

@@ -35,7 +35,6 @@ import javax.inject.Named;
 import javax.inject.Provider;
 import java.io.IOException;
 import java.nio.file.NoSuchFileException;
-import java.nio.file.NotDirectoryException;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.EnumSet;
@@ -123,9 +122,6 @@ public class Vault {
 	}
 
 	public synchronized void unlock(CharSequence passphrase) throws CryptoException, IOException, VolumeException, InvalidMountPointException {
-		if (vaultSettings.useCustomMountPath().get() && Strings.isNullOrEmpty(vaultSettings.customMountPath().get())) {
-			throw new NotDirectoryException("");
-		}
 		CryptoFileSystem fs = getCryptoFileSystem(passphrase);
 		volume = volumeProvider.get();
 		volume.mount(fs, getEffectiveMountFlags());

+ 38 - 9
main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockWorkflow.java

@@ -29,6 +29,7 @@ import javax.inject.Named;
 import java.io.IOException;
 import java.nio.CharBuffer;
 import java.nio.file.DirectoryNotEmptyException;
+import java.nio.file.FileAlreadyExistsException;
 import java.nio.file.NotDirectoryException;
 import java.util.Arrays;
 import java.util.Optional;
@@ -84,10 +85,6 @@ public class UnlockWorkflow extends Task<Boolean> {
 				cancel(false); // set Tasks state to cancelled
 				return false;
 			}
-		} catch (NotDirectoryException | DirectoryNotEmptyException thrown) {
-			InvalidMountPointException e = new InvalidMountPointException(thrown);
-			handleInvalidMountPoint(e);
-			throw e; // rethrow to trigger correct exception handling in Task
 		} catch (InvalidMountPointException e) {
 			handleInvalidMountPoint(e);
 			throw e; // rethrow to trigger correct exception handling in Task
@@ -159,17 +156,49 @@ public class UnlockWorkflow extends Task<Boolean> {
 		}
 	}
 
-	private void handleInvalidMountPoint(InvalidMountPointException e) {
+	private void handleInvalidMountPoint(InvalidMountPointException impExc) {
 		MountPointRequirement requirement = vault.getMountPointRequirement();
 		assert requirement != MountPointRequirement.NONE; //An invalid MountPoint with no required MountPoint doesn't seem sensible
 		assert requirement != MountPointRequirement.PARENT_OPT_MOUNT_POINT; //Not implemented anywhere (yet)
 
-		if (requirement == MountPointRequirement.EMPTY_MOUNT_POINT) {
-			LOG.error("Unlock failed. Mount point not an empty directory or doesn't exist: {}", e.getMessage());
-		} else {
-			LOG.error("Unlock failed. Mount point/folder already exists or parent folder doesn't exist: {}", e.getMessage());
+		Throwable cause = impExc.getCause();
+		//Cause is either null (cause the IMPE was thrown directly, e.g. because no MPC succeeded)
+		//or the cause was not an Exception (but some other kind of Throwable)
+		//Either way: Handle as generic error
+		if(!(cause instanceof Exception)) {
+			handleGenericError(impExc);
+			return;
+		}
+
+		//From here on handle the cause, not the caught exception
+		if(cause instanceof NotDirectoryException) {
+			if(requirement == MountPointRequirement.PARENT_NO_MOUNT_POINT) {
+				LOG.error("Unlock failed. Parent folder is missing: {}", cause.getMessage());
+			} else {
+				LOG.error("Unlock failed. Mountpoint doesn't exist (needs to be a folder): {}", cause.getMessage());
+			}
+			showInvalidMountPointScene();
+			return;
+		}
+
+		if(cause instanceof FileAlreadyExistsException) {
+			LOG.error("Unlock failed. Mountpoint already exists: {}", cause.getMessage());
+			showInvalidMountPointScene();
+			return;
+		}
+
+		if(cause instanceof DirectoryNotEmptyException) {
+			LOG.error("Unlock failed. Mountpoint not an empty directory: {}", cause.getMessage());
+			showInvalidMountPointScene();
+			return;
 		}
 
+		//Everything else (especially IOException) results in a generic error
+		//This must be done after the other exceptions because they extend IOException...
+		handleGenericError(cause);
+	}
+
+	private void showInvalidMountPointScene() {
 		Platform.runLater(() -> {
 			window.setScene(invalidMountPointScene.get());
 		});

+ 1 - 1
main/ui/src/main/resources/i18n/strings.properties

@@ -101,7 +101,7 @@ unlock.success.rememberChoice=Remember choice, don't show this again
 unlock.success.revealBtn=Reveal Vault
 ## Invalid Mount Point
 unlock.error.invalidMountPoint.notExisting=Mount point is not an empty directory or doesn't exist: %s
-unlock.error.invalidMountPoint.existing=Mount point/folder already exists or parent folder doesn't exist: %s
+unlock.error.invalidMountPoint.existing=Mount point/folder already exists or parent folder is missing: %s
 
 # Migration
 migration.title=Upgrade Vault