From da58fee41619d4a68258b557ca4379efcd59d6e0 Mon Sep 17 00:00:00 2001 From: 4pr0n Date: Sat, 7 Feb 2015 23:39:27 -0800 Subject: [PATCH] Error handling and warning when history can't be loaded --- src/main/java/com/rarchives/ripme/ui/History.java | 3 +++ src/main/java/com/rarchives/ripme/ui/MainWindow.java | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/src/main/java/com/rarchives/ripme/ui/History.java b/src/main/java/com/rarchives/ripme/ui/History.java index dfcfa2ef..79c31836 100644 --- a/src/main/java/com/rarchives/ripme/ui/History.java +++ b/src/main/java/com/rarchives/ripme/ui/History.java @@ -12,6 +12,7 @@ import java.util.List; import org.apache.commons.io.IOUtils; import org.json.JSONArray; +import org.json.JSONException; import org.json.JSONObject; public class History { @@ -100,6 +101,8 @@ public class History { String jsonString = IOUtils.toString(is); JSONArray jsonArray = new JSONArray(jsonString); fromJSON(jsonArray); + } catch (JSONException e) { + throw new IOException("Failed to load JSON file " + filename + ": " + e.getMessage(), e); } finally { is.close(); } diff --git a/src/main/java/com/rarchives/ripme/ui/MainWindow.java b/src/main/java/com/rarchives/ripme/ui/MainWindow.java index 3297f663..40051186 100644 --- a/src/main/java/com/rarchives/ripme/ui/MainWindow.java +++ b/src/main/java/com/rarchives/ripme/ui/MainWindow.java @@ -879,6 +879,13 @@ public class MainWindow implements Runnable, RipStatusHandler { HISTORY.fromFile("history.json"); } catch (IOException e) { logger.error("Failed to load history from file " + historyFile, e); + JOptionPane.showMessageDialog(null, + "RipMe failed to load the history file at " + historyFile.getAbsolutePath() + "\n\n" + + "Error: " + e.getMessage() + "\n\n" + + "Closing RipMe will automatically overwrite the contents of this file,\n" + + "so you may want to back the file up before closing RipMe!", + "RipMe - history load failure", + JOptionPane.ERROR_MESSAGE); } } else {