Jelajahi Sumber

Added default Errorhandler to all Tasks and Services

JaniruTEC 4 tahun lalu
induk
melakukan
551d9d1af1

+ 2 - 0
main/ui/src/main/java/org/cryptomator/ui/common/Tasks.java

@@ -174,6 +174,8 @@ public class Tasks {
 
 		RestartingService(Supplier<Task<T>> taskFactory) {
 			this.taskFactory = taskFactory;
+
+			setOnFailed(event -> LOG.error("Failed to execute service", getException()));
 		}
 
 		@Override

+ 4 - 0
main/ui/src/main/java/org/cryptomator/ui/common/VaultService.java

@@ -108,6 +108,8 @@ public class VaultService {
 		 */
 		public RevealVaultTask(Vault vault) {
 			this.vault = vault;
+
+			setOnFailed(evt -> LOG.error("Failed to reveal " + vault.getDisplayName(), getException()));
 		}
 
 		@Override
@@ -126,6 +128,8 @@ public class VaultService {
 
 		public WaitForTasksTask(Collection<Task<Vault>> tasks) {
 			this.startedTasks = List.copyOf(tasks);
+
+			setOnFailed(event -> LOG.error("Failed to lock multiple vaults", getException()));
 		}
 
 		@Override

+ 5 - 0
main/ui/src/main/java/org/cryptomator/ui/fxapp/UpdateCheckerModule.java

@@ -11,6 +11,8 @@ import javafx.concurrent.Task;
 import javafx.util.Duration;
 import org.apache.commons.lang3.SystemUtils;
 import org.cryptomator.common.settings.Settings;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import javax.inject.Named;
 import java.net.URI;
@@ -22,6 +24,8 @@ import java.util.concurrent.ExecutorService;
 @Module
 public abstract class UpdateCheckerModule {
 
+	private static final Logger LOG = LoggerFactory.getLogger(UpdateCheckerModule.class);
+
 	private static final URI LATEST_VERSION_URI = URI.create("https://api.cryptomator.org/updates/latestVersion.json");
 	private static final Duration UPDATE_CHECK_INTERVAL = Duration.hours(3);
 	private static final Duration DISABLED_UPDATE_CHECK_INTERVAL = Duration.hours(100000); // Duration.INDEFINITE leads to overflows...
@@ -69,6 +73,7 @@ public abstract class UpdateCheckerModule {
 				return new UpdateCheckerTask(httpClient, checkForUpdatesRequest);
 			}
 		};
+		service.setOnFailed(event -> LOG.error("Failed to execute update service", service.getException()));
 		service.setExecutor(executor);
 		service.periodProperty().bind(period);
 		return service;

+ 6 - 0
main/ui/src/main/java/org/cryptomator/ui/fxapp/UpdateCheckerTask.java

@@ -6,6 +6,8 @@ import com.google.gson.GsonBuilder;
 import com.google.gson.reflect.TypeToken;
 import javafx.concurrent.Task;
 import org.apache.commons.lang3.SystemUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -19,6 +21,8 @@ import java.util.Map;
 
 public class UpdateCheckerTask extends Task<String> {
 
+	private static final Logger LOG = LoggerFactory.getLogger(UpdateCheckerTask.class);
+
 	private static final long MAX_RESPONSE_SIZE = 10 * 1024; // 10kb should be sufficient. protect against flooding
 	private static final Gson GSON = new GsonBuilder().setLenient().create();
 
@@ -28,6 +32,8 @@ public class UpdateCheckerTask extends Task<String> {
 	UpdateCheckerTask(HttpClient httpClient, HttpRequest checkForUpdatesRequest) {
 		this.httpClient = httpClient;
 		this.checkForUpdatesRequest = checkForUpdatesRequest;
+
+		setOnFailed(event -> LOG.error("Failed to check for updates", getException()));
 	}
 
 	@Override

+ 2 - 0
main/ui/src/main/java/org/cryptomator/ui/preferences/GeneralPreferencesController.java

@@ -161,6 +161,8 @@ public class GeneralPreferencesController implements FxController {
 		public ToggleAutoStartTask(AutoStartStrategy autoStart, boolean enable) {
 			this.autoStart = autoStart;
 			this.enable = enable;
+
+			setOnFailed(event -> LOG.error("Failed to toggle Autostart", getException()));
 		}
 
 		@Override

+ 4 - 0
main/ui/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyCreationController.java

@@ -71,6 +71,10 @@ public class RecoveryKeyCreationController implements FxController {
 
 	private class RecoveryKeyCreationTask extends Task<String> {
 
+		private RecoveryKeyCreationTask() {
+			setOnFailed(event -> LOG.error("Failed to create recovery key", getException()));
+		}
+
 		@Override
 		protected String call() throws IOException {
 			return recoveryKeyFactory.createRecoveryKey(vault.getPath(), passwordField.getCharacters());

+ 4 - 0
main/ui/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyResetPasswordController.java

@@ -77,6 +77,10 @@ public class RecoveryKeyResetPasswordController implements FxController {
 
 	private class ResetPasswordTask extends Task<Void> {
 
+		private ResetPasswordTask() {
+			setOnFailed(event -> LOG.error("Failed to reset password", getException()));
+		}
+
 		@Override
 		protected Void call() throws IOException, IllegalArgumentException {
 			recoveryKeyFactory.resetPasswordWithRecoveryKey(vault.getPath(), recoveryKey.get(), newPassword.get());