From 8027e870780ffb6c50d52766a07d4cd87688e7a5 Mon Sep 17 00:00:00 2001 From: Brettflan Date: Fri, 13 Jan 2012 05:48:03 -0600 Subject: [PATCH] Errors loading conf.json are handled better now, allowing Factions to continue on to loading board.json instead of losing it Also, the bad conf.json file is backed up to conf.json_bad so it can potentially be recovered --- .../factions/zcore/util/Persist.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/com/massivecraft/factions/zcore/util/Persist.java b/src/com/massivecraft/factions/zcore/util/Persist.java index 89c6aafd..3d7fd8d7 100644 --- a/src/com/massivecraft/factions/zcore/util/Persist.java +++ b/src/com/massivecraft/factions/zcore/util/Persist.java @@ -86,6 +86,13 @@ public class Persist { if (loaded == null) { p.log(Level.WARNING, "Using default as I failed to load: "+file); + + // backup bad file, so user can attempt to recover their changes from it + File backup = new File(file.getPath()+"_bad"); + if (backup.exists()) backup.delete(); + p.log(Level.WARNING, "Backing up copy of bad file to: "+backup); + file.renameTo(backup); + return def; } @@ -129,9 +136,17 @@ public class Persist { return null; } - T instance = p.gson.fromJson(content, clazz); - - return instance; + try + { + T instance = p.gson.fromJson(content, clazz); + return instance; + } + catch (Exception ex) + { // output the error message rather than full stack trace; error parsing the file, most likely + p.log(Level.WARNING, ex.getMessage()); + } + + return null; }