removed most of the usages of e.printStrackTrace() and e.getMessage() ...

... by using appropriate logging methods
master
Stefan Dollase 2016-11-21 03:30:50 +01:00
parent 05206b3fea
commit 5fcfe5cb43
18 changed files with 51 additions and 83 deletions

View File

@ -170,8 +170,7 @@ public class Amidst {
try {
new Application(parameters, metadata, settings).run();
} catch (DotMinecraftDirectoryNotFoundException e) {
AmidstLogger.warn(e.getMessage());
e.printStackTrace();
AmidstLogger.warn(e);
AmidstMessageBox.displayError(
"Please install Minecraft",
"Amidst is not able to find your '.minecraft' directory, but it requires a working Minecraft installation.");

View File

@ -20,8 +20,7 @@ public class License {
try {
return ResourceLoader.getResourceAsString(path);
} catch (IOException e) {
AmidstLogger.warn("Unable to read license for '" + name + "' at '" + path + "'.");
e.printStackTrace();
AmidstLogger.warn(e, "Unable to read license for '" + name + "' at '" + path + "'.");
return "License text is missing.";
}
}

View File

@ -331,7 +331,7 @@ public class Actions {
try {
ImageIO.write(image, "png", file);
} catch (IOException e) {
e.printStackTrace();
AmidstLogger.warn(e);
mainWindow.displayException(e);
}
}

View File

@ -25,6 +25,7 @@ import amidst.gui.main.viewer.ViewerFacade;
import amidst.gui.main.viewer.ViewerFacadeBuilder;
import amidst.gui.seedsearcher.SeedSearcher;
import amidst.gui.seedsearcher.SeedSearcherWindow;
import amidst.logging.AmidstLogger;
import amidst.logging.AmidstMessageBox;
import amidst.mojangapi.MojangApi;
import amidst.mojangapi.file.MojangApiParsingException;
@ -148,7 +149,7 @@ public class MainWindow {
try {
setWorld(mojangApi.createWorldFromSeed(worldSeed, worldType));
} catch (IllegalStateException | MinecraftInterfaceException e) {
e.printStackTrace();
AmidstLogger.warn(e);
displayException(e);
}
}
@ -158,7 +159,7 @@ public class MainWindow {
try {
setWorld(mojangApi.createWorldFromSaveGame(file));
} catch (IllegalStateException | MinecraftInterfaceException | IOException | MojangApiParsingException e) {
e.printStackTrace();
AmidstLogger.warn(e);
displayException(e);
}
}

View File

@ -108,7 +108,7 @@ public class UpdatePrompt {
@CalledOnlyBy(AmidstThread.EDT)
private void displayError(Exception e) {
e.printStackTrace();
AmidstLogger.warn(e);
exceptionConsumer.accept(e);
}

View File

@ -75,10 +75,8 @@ public class CursorInformationWidget extends TextWidget {
try {
return Biome.getByIndex(biome).getName();
} catch (UnknownBiomeIndexException e) {
String message = e.getMessage();
AmidstLogger.error(message);
AmidstMessageBox.displayError("Error", message);
e.printStackTrace();
AmidstLogger.error(e);
AmidstMessageBox.displayError("Error", e);
return UNKNOWN_BIOME_NAME;
}
} else {

View File

@ -59,7 +59,7 @@ public class LocalProfileComponent extends ProfileComponent {
versionDirectory = profile.createValidVersionDirectory(mojangApi);
return true;
} catch (FileNotFoundException e) {
AmidstLogger.warn(e.getMessage());
AmidstLogger.warn(e);
return false;
}
}
@ -89,18 +89,19 @@ public class LocalProfileComponent extends ProfileComponent {
String possibleModProfiles = ".*(optifine|forge).*";
if (Pattern.matches(possibleModProfiles, getVersionName().toLowerCase(Locale.ENGLISH))) {
AmidstLogger.error("Amidst does not support modded Minecraft profiles! Please select or create an unmodded Minecraft profile via the Minecraft Launcher.");
AmidstMessageBox.displayError("Error", "Amidst does not support modded Minecraft profiles! Please select or create an unmodded Minecraft profile via the Minecraft Launcher.");
AmidstLogger.error(
"Amidst does not support modded Minecraft profiles! Please select or create an unmodded Minecraft profile via the Minecraft Launcher.");
AmidstMessageBox.displayError(
"Error",
"Amidst does not support modded Minecraft profiles! Please select or create an unmodded Minecraft profile via the Minecraft Launcher.");
return false;
}
mojangApi.set(getProfileName(), profileDirectory, versionDirectory);
return true;
} catch (LocalMinecraftInterfaceCreationException e) {
String message = e.getMessage();
AmidstLogger.error(message);
AmidstMessageBox.displayError("Error", message);
e.printStackTrace();
AmidstLogger.error(e);
AmidstMessageBox.displayError("Error", e);
return false;
}
}

View File

@ -155,9 +155,8 @@ public class ProfileSelectWindow {
@CalledOnlyBy(AmidstThread.EDT)
private void scanAndLoadProfilesFailed(Exception e) {
AmidstLogger.error("Error reading launcher_profiles.json");
AmidstMessageBox.displayError("Error", "Error reading launcher_profiles.json");
e.printStackTrace();
AmidstLogger.error(e, "Error reading launcher_profiles.json");
AmidstMessageBox.displayError("Error", e, "Error reading launcher_profiles.json");
profileSelectPanel.setEmptyMessage("Failed loading");
}

View File

@ -6,6 +6,7 @@ import amidst.documentation.AmidstThread;
import amidst.documentation.CalledOnlyBy;
import amidst.documentation.NotThreadSafe;
import amidst.gui.main.MainWindow;
import amidst.logging.AmidstLogger;
import amidst.mojangapi.MojangApi;
import amidst.mojangapi.minecraftinterface.MinecraftInterfaceException;
import amidst.mojangapi.world.World;
@ -67,7 +68,7 @@ public class SeedSearcher {
try {
doSearch(reporter, configuration);
} catch (IllegalStateException | MinecraftInterfaceException e) {
e.printStackTrace();
AmidstLogger.warn(e);
mainWindow.displayException(e);
} finally {
this.isSearching = false;

View File

@ -71,8 +71,7 @@ public class FileLogger implements Logger {
@CalledOnlyBy(AmidstThread.STARTUP)
private void disableBecauseFileCreationThrowsException(IOException e) {
AmidstLogger.warn("Unable to create new file at: " + file + " disabling logging to file.");
e.printStackTrace();
AmidstLogger.warn(e, "Unable to create new file at: " + file + " disabling logging to file.");
}
@CalledOnlyBy(AmidstThread.STARTUP)
@ -117,8 +116,7 @@ public class FileLogger implements Logger {
try (FileWriter writer = new FileWriter(file, true)) {
writer.append(logMessage);
} catch (IOException e) {
AmidstLogger.warn("Unable to write to log file.");
e.printStackTrace();
AmidstLogger.warn(e, "Unable to write to log file.");
}
}

View File

@ -26,8 +26,7 @@ public enum LibraryFinder {
result.add(libraryFile.toURI().toURL());
AmidstLogger.info("Found library: " + libraryFile);
} catch (MalformedURLException e) {
AmidstLogger.warn("Unable to convert library file to URL: " + libraryFile);
e.printStackTrace();
AmidstLogger.warn(e, "Unable to convert library file to URL: " + libraryFile);
}
} else {
AmidstLogger.info("Skipping library: " + library.getName());

View File

@ -78,8 +78,7 @@ public class VersionListEntryJson {
downloadServer(prefix);
return true;
} catch (IOException e) {
AmidstLogger.warn("unable to download server: " + id);
e.printStackTrace();
AmidstLogger.warn(e, "unable to download server: " + id);
}
return false;
}
@ -89,8 +88,7 @@ public class VersionListEntryJson {
downloadClient(prefix);
return true;
} catch (IOException e) {
AmidstLogger.warn("unable to download client: " + id);
e.printStackTrace();
AmidstLogger.warn(e, "unable to download client: " + id);
}
return false;
}

View File

@ -82,8 +82,7 @@ public class SeedHistoryLogger {
try {
file.createNewFile();
} catch (IOException e) {
AmidstLogger.warn("Unable to create seed history file: " + file);
e.printStackTrace();
AmidstLogger.warn(e, "Unable to create seed history file: " + file);
}
}
@ -91,8 +90,7 @@ public class SeedHistoryLogger {
try (PrintStream stream = new PrintStream(new FileOutputStream(file, true))) {
stream.println(line);
} catch (IOException e) {
AmidstLogger.warn("Unable to write to seed history file: " + file);
e.printStackTrace();
AmidstLogger.warn(e, "Unable to write to seed history file: " + file);
}
}
}

View File

@ -35,16 +35,12 @@ public class TempleWorldIconTypeProvider implements WorldIconTypeProvider<Void>
return null;
}
} catch (UnknownBiomeIndexException e) {
String message = e.getMessage();
AmidstLogger.error(message);
AmidstMessageBox.displayError("Error", message);
e.printStackTrace();
AmidstLogger.error(e);
AmidstMessageBox.displayError("Error", e);
return null;
} catch (MinecraftInterfaceException e) {
String message = e.getMessage();
AmidstLogger.error(message);
AmidstMessageBox.displayError("Error", message);
e.printStackTrace();
AmidstLogger.error(e);
AmidstMessageBox.displayError("Error", e);
return null;
}
}

View File

@ -31,10 +31,8 @@ public class BiomeDataOracle {
try {
copyToResult(result, width, height, getBiomeData(left, top, width, height, useQuarterResolution));
} catch (MinecraftInterfaceException e) {
String message = e.getMessage();
AmidstLogger.error(message);
AmidstMessageBox.displayError("Error", message);
e.printStackTrace();
AmidstLogger.error(e);
AmidstMessageBox.displayError("Error", e);
}
}
}
@ -59,16 +57,12 @@ public class BiomeDataOracle {
try {
return validBiomes.contains(getBiomeAt(x, y));
} catch (UnknownBiomeIndexException e) {
String message = e.getMessage();
AmidstLogger.error(message);
AmidstMessageBox.displayError("Error", message);
e.printStackTrace();
AmidstLogger.error(e);
AmidstMessageBox.displayError("Error", e);
return false;
} catch (MinecraftInterfaceException e) {
String message = e.getMessage();
AmidstLogger.error(message);
AmidstMessageBox.displayError("Error", message);
e.printStackTrace();
AmidstLogger.error(e);
AmidstMessageBox.displayError("Error", e);
return false;
}
}
@ -93,16 +87,12 @@ public class BiomeDataOracle {
}
return true;
} catch (UnknownBiomeIndexException e) {
String message = e.getMessage();
AmidstLogger.error(message);
AmidstMessageBox.displayError("Error", message);
e.printStackTrace();
AmidstLogger.error(e);
AmidstMessageBox.displayError("Error", e);
return false;
} catch (MinecraftInterfaceException e) {
String message = e.getMessage();
AmidstLogger.error(message);
AmidstMessageBox.displayError("Error", message);
e.printStackTrace();
AmidstLogger.error(e);
AmidstMessageBox.displayError("Error", e);
return false;
}
}
@ -137,16 +127,12 @@ public class BiomeDataOracle {
}
return result;
} catch (UnknownBiomeIndexException e) {
String message = e.getMessage();
AmidstLogger.error(message);
AmidstMessageBox.displayError("Error", message);
e.printStackTrace();
AmidstLogger.error(e);
AmidstMessageBox.displayError("Error", e);
return null;
} catch (MinecraftInterfaceException e) {
String message = e.getMessage();
AmidstLogger.error(message);
AmidstMessageBox.displayError("Error", message);
e.printStackTrace();
AmidstLogger.error(e);
AmidstMessageBox.displayError("Error", e);
return null;
}
}

View File

@ -49,8 +49,7 @@ public class Player {
return false;
}
} catch (MojangApiParsingException e) {
AmidstLogger.warn("error while writing player location for player: " + getPlayerName());
e.printStackTrace();
AmidstLogger.warn(e, "error while writing player location for player: " + getPlayerName());
return false;
}
}
@ -78,8 +77,7 @@ public class Player {
loadLocation();
return true;
} catch (IOException | MojangApiParsingException e) {
AmidstLogger.warn("error while reading player location for player: " + getPlayerName());
e.printStackTrace();
AmidstLogger.warn(e, "error while reading player location for player: " + getPlayerName());
return false;
}
}

View File

@ -101,8 +101,7 @@ public class BiomeProfileDirectory {
}
profile.validate();
} catch (JsonSyntaxException | JsonIOException | IOException | NullPointerException e) {
AmidstLogger.warn("Unable to load file: " + file);
e.printStackTrace();
AmidstLogger.warn(e, "Unable to load file: " + file);
}
}
return profile;

View File

@ -18,10 +18,8 @@ public class BiomeProfileSelection {
try {
return getBiomeColor(index);
} catch (UnknownBiomeIndexException e) {
String message = e.getMessage();
AmidstLogger.error(message);
AmidstMessageBox.displayError("Error", message);
e.printStackTrace();
AmidstLogger.error(e);
AmidstMessageBox.displayError("Error", e);
return BiomeColor.unknown();
}
}