Merge pull request #1384 from cryptomator/fix/missing-exceptions

Fix/missing exceptions
This commit is contained in:
JaniruTEC
2020-10-29 16:58:51 +01:00
committed by GitHub
9 changed files with 46 additions and 8 deletions

View File

@@ -59,6 +59,10 @@ public class VaultStats {
private class UpdateStatsService extends ScheduledService<Optional<CryptoFileSystemStats>> {
private UpdateStatsService() {
setOnFailed(event -> LOG.error("Error in UpdateStateService.", getException()));
}
@Override
protected Task<Optional<CryptoFileSystemStats>> createTask() {
return new Task<>() {

View File

@@ -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

View File

@@ -69,7 +69,6 @@ public class VaultService {
public Task<Vault> createLockTask(Vault vault, boolean forced) {
Task<Vault> task = new LockVaultTask(vault, forced);
task.setOnSucceeded(evt -> LOG.info("Locked {}", vault.getDisplayName()));
task.setOnFailed(evt -> LOG.error("Failed to lock " + vault.getDisplayName(), evt.getSource().getException()));
return task;
}
@@ -109,6 +108,8 @@ public class VaultService {
*/
public RevealVaultTask(Vault vault) {
this.vault = vault;
setOnFailed(evt -> LOG.error("Failed to reveal " + vault.getDisplayName(), getException()));
}
@Override
@@ -127,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
@@ -165,6 +168,8 @@ public class VaultService {
public LockVaultTask(Vault vault, boolean forced) {
this.vault = vault;
this.forced = forced;
setOnFailed(event -> LOG.error("Failed to lock " + vault.getDisplayName(), event.getSource().getException()));
}
@Override

View File

@@ -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;

View File

@@ -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

View File

@@ -109,7 +109,10 @@ public class GeneralPreferencesController implements FxController {
autoStartStrategy.ifPresent(autoStart -> {
boolean enableAutoStart = autoStartCheckbox.isSelected();
Task<Void> toggleTask = new ToggleAutoStartTask(autoStart, enableAutoStart);
toggleTask.setOnFailed(evt -> autoStartCheckbox.setSelected(!enableAutoStart)); // restore previous state
toggleTask.setOnFailed(event -> {
autoStartCheckbox.setSelected(!enableAutoStart); // restore previous state
LOG.error("Failed to toggle autostart.", event.getSource().getException());
});
executor.execute(toggleTask);
});
}
@@ -158,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

View File

@@ -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());

View File

@@ -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());

View File

@@ -73,6 +73,15 @@ public class UnlockWorkflow extends Task<Boolean> {
this.successScene = successScene;
this.invalidMountPointScene = invalidMountPointScene;
this.errorComponent = errorComponent;
setOnFailed(event -> {
Throwable throwable = event.getSource().getException();
if (throwable instanceof InvalidMountPointException) {
handleInvalidMountPoint((InvalidMountPointException) throwable);
} else {
handleGenericError(throwable);
}
});
}
@Override
@@ -85,12 +94,6 @@ public class UnlockWorkflow extends Task<Boolean> {
cancel(false); // set Tasks state to cancelled
return false;
}
} catch (InvalidMountPointException e) {
handleInvalidMountPoint(e);
throw e; // rethrow to trigger correct exception handling in Task
} catch (Exception e) {
handleGenericError(e);
throw e; // rethrow to trigger correct exception handling in Task
} finally {
wipePassword(password.get());
wipePassword(savedPassword.orElse(null));