Error handling and warning when history can't be loaded

This commit is contained in:
4pr0n 2015-02-07 23:39:27 -08:00
parent 39a9edd1fa
commit da58fee416
2 changed files with 10 additions and 0 deletions

View File

@ -12,6 +12,7 @@ import java.util.List;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
public class History { public class History {
@ -100,6 +101,8 @@ public class History {
String jsonString = IOUtils.toString(is); String jsonString = IOUtils.toString(is);
JSONArray jsonArray = new JSONArray(jsonString); JSONArray jsonArray = new JSONArray(jsonString);
fromJSON(jsonArray); fromJSON(jsonArray);
} catch (JSONException e) {
throw new IOException("Failed to load JSON file " + filename + ": " + e.getMessage(), e);
} finally { } finally {
is.close(); is.close();
} }

View File

@ -879,6 +879,13 @@ public class MainWindow implements Runnable, RipStatusHandler {
HISTORY.fromFile("history.json"); HISTORY.fromFile("history.json");
} catch (IOException e) { } catch (IOException e) {
logger.error("Failed to load history from file " + historyFile, 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 { else {