From: David ‘Bombe’ Roden Date: Mon, 17 Mar 2014 19:38:23 +0000 (+0100) Subject: Delete JSON file in case of an error. X-Git-Tag: v2~259 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=c52aa3cb7bd06a5be45bf9e771c01c1be593dc07;p=rhynodge.git Delete JSON file in case of an error. --- diff --git a/src/main/java/net/pterodactylus/rhynodge/states/StateManager.java b/src/main/java/net/pterodactylus/rhynodge/states/StateManager.java index 35125bb..a52e74d 100644 --- a/src/main/java/net/pterodactylus/rhynodge/states/StateManager.java +++ b/src/main/java/net/pterodactylus/rhynodge/states/StateManager.java @@ -96,8 +96,9 @@ public class StateManager { * The state to save */ public void saveState(String reactionName, State state) { + File stateFile = null; try { - File stateFile = stateFile(reactionName, "last"); + stateFile = stateFile(reactionName, "last"); objectMapper.writeValue(stateFile, state); if (state.success()) { stateFile = stateFile(reactionName, "success"); @@ -105,10 +106,13 @@ public class StateManager { } } catch (JsonGenerationException jge1) { logger.warn(String.format("State for Reaction “%s” could not be generated.", reactionName), jge1); + stateFile.delete(); } catch (JsonMappingException jme1) { logger.warn(String.format("State for Reaction “%s” could not be generated.", reactionName), jme1); + stateFile.delete(); } catch (IOException ioe1) { logger.warn(String.format("State for Reaction “%s” could not be written.", reactionName)); + stateFile.delete(); } }