startup error: make error copyable, improve code

This commit is contained in:
Bixilon 2020-11-04 14:13:48 +01:00
parent e805f72e7c
commit f9c791cf39
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
3 changed files with 18 additions and 21 deletions

View File

@ -35,6 +35,7 @@ import de.bixilon.minosoft.util.task.Task;
import de.bixilon.minosoft.util.task.TaskImportance;
import javafx.application.Platform;
import javafx.scene.control.Dialog;
import javafx.scene.control.TextArea;
import javafx.stage.Stage;
import java.io.IOException;
@ -56,21 +57,14 @@ public final class Minosoft {
taskWorker.setFatalError((exception) -> {
Log.fatal("Critical error occurred while preparing. Exit");
if (StartProgressWindow.toolkitLatch.getCount() == 2) {
try {
try {
if (StartProgressWindow.toolkitLatch.getCount() == 2) {
StartProgressWindow.start();
} catch (InterruptedException e2) {
e2.printStackTrace();
System.exit(1);
}
}
if (StartProgressWindow.toolkitLatch.getCount() > 0) {
try {
StartProgressWindow.toolkitLatch.await();
} catch (InterruptedException e2) {
e2.printStackTrace();
System.exit(1);
}
StartProgressWindow.toolkitLatch.await();
} catch (InterruptedException e) {
e.printStackTrace();
System.exit(1);
}
// hide all other gui parts
StartProgressWindow.hideDialog();
@ -80,7 +74,10 @@ public final class Minosoft {
// Do not translate this, translations might fail to load...
dialog.setTitle("Critical Error");
dialog.setHeaderText("An error occurred while starting Minosoft");
dialog.setContentText(exception.getClass().getCanonicalName() + ": " + exception.getLocalizedMessage());
TextArea text = new TextArea(exception.getClass().getCanonicalName() + ": " + exception.getLocalizedMessage());
text.setEditable(false);
text.setWrapText(true);
dialog.getDialogPane().setContent(text);
Stage stage = (Stage) dialog.getDialogPane().getScene().getWindow();
stage.getIcons().add(GUITools.logo);

View File

@ -187,7 +187,7 @@ public class Configuration {
return config;
}
private void migrateConfiguration() {
private void migrateConfiguration() throws ConfigMigrationException {
int configVersion = getInt(ConfigurationPaths.IntegerPaths.GENERAL_CONFIG_VERSION);
Log.info(String.format("Migrating config from version %d to %d", configVersion, LATEST_CONFIG_VERSION));
for (int nextVersion = configVersion + 1; nextVersion <= LATEST_CONFIG_VERSION; nextVersion++) {
@ -199,10 +199,10 @@ public class Configuration {
}
private void migrateConfiguration(int nextVersion) {
private void migrateConfiguration(int nextVersion) throws ConfigMigrationException {
switch (nextVersion) {
// ToDo
default -> throw new IllegalArgumentException("Can not migrate config: Unknown config version " + nextVersion);
default -> throw new ConfigMigrationException("Can not migrate config: Unknown config version " + nextVersion);
}
}
}

View File

@ -253,12 +253,12 @@ public final class Util {
return new ThreadFactoryBuilder().setNameFormat(threadName + "#%d").build();
}
public static void createParentFolderIfNotExist(String file) {
createParentFolderIfNotExist(new File(file));
public static boolean createParentFolderIfNotExist(String file) {
return createParentFolderIfNotExist(new File(file));
}
public static void createParentFolderIfNotExist(File file) {
file.getParentFile().mkdirs();
public static boolean createParentFolderIfNotExist(File file) {
return file.getParentFile().mkdirs();
}
public static String generateRandomString(int length) {