Added default Errorhandler to all Tasks and Services

This commit is contained in:
JaniruTEC
2020-10-28 16:21:14 +01:00
parent 0acc8ddb0a
commit 551d9d1af1
7 changed files with 27 additions and 0 deletions
@@ -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
@@ -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
@@ -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,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
@@ -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
@@ -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());
@@ -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());