From c7123df79d9c6b6b011647561c1099dffda1dcac Mon Sep 17 00:00:00 2001 From: catbref Date: Tue, 26 Feb 2019 11:20:44 +0000 Subject: [PATCH] Better logging for settings/blockchain JSON file parsing --- src/main/java/org/qora/block/BlockChain.java | 12 ++++++++++++ src/main/java/org/qora/settings/Settings.java | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/main/java/org/qora/block/BlockChain.java b/src/main/java/org/qora/block/BlockChain.java index cb812e01..0c7681b7 100644 --- a/src/main/java/org/qora/block/BlockChain.java +++ b/src/main/java/org/qora/block/BlockChain.java @@ -11,6 +11,7 @@ import java.util.Map; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; +import javax.xml.bind.UnmarshalException; import javax.xml.bind.Unmarshaller; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; @@ -19,6 +20,7 @@ import javax.xml.transform.stream.StreamSource; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.eclipse.persistence.exceptions.XMLMarshalException; import org.eclipse.persistence.jaxb.JAXBContextFactory; import org.eclipse.persistence.jaxb.UnmarshallerProperties; import org.qora.data.block.BlockData; @@ -132,6 +134,16 @@ public class BlockChain { // Attempt to unmarshal JSON stream to BlockChain config blockchain = unmarshaller.unmarshal(json, BlockChain.class).getValue(); + } catch (UnmarshalException e) { + Throwable linkedException = e.getLinkedException(); + if (linkedException instanceof XMLMarshalException) { + String message = ((XMLMarshalException) linkedException).getInternalException().getLocalizedMessage(); + LOGGER.error(message); + throw new RuntimeException(message); + } + + LOGGER.error("Unable to process blockchain config file", e); + throw new RuntimeException("Unable to process blockchain config file", e); } catch (FileNotFoundException e) { LOGGER.error("Blockchain config file not found: " + filename); throw new RuntimeException("Blockchain config file not found: " + filename); diff --git a/src/main/java/org/qora/settings/Settings.java b/src/main/java/org/qora/settings/Settings.java index b0561923..e975cf7a 100644 --- a/src/main/java/org/qora/settings/Settings.java +++ b/src/main/java/org/qora/settings/Settings.java @@ -8,6 +8,7 @@ import java.io.Reader; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; +import javax.xml.bind.UnmarshalException; import javax.xml.bind.Unmarshaller; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; @@ -15,6 +16,7 @@ import javax.xml.transform.stream.StreamSource; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.eclipse.persistence.exceptions.XMLMarshalException; import org.eclipse.persistence.jaxb.JAXBContextFactory; import org.eclipse.persistence.jaxb.UnmarshallerProperties; import org.qora.block.BlockChain; @@ -112,6 +114,16 @@ public class Settings { } catch (FileNotFoundException e) { LOGGER.error("Settings file not found: " + path + filename); throw new RuntimeException("Settings file not found: " + path + filename); + } catch (UnmarshalException e) { + Throwable linkedException = e.getLinkedException(); + if (linkedException instanceof XMLMarshalException) { + String message = ((XMLMarshalException) linkedException).getInternalException().getLocalizedMessage(); + LOGGER.error(message); + throw new RuntimeException(message); + } + + LOGGER.error("Unable to process settings file", e); + throw new RuntimeException("Unable to process settings file", e); } catch (JAXBException e) { LOGGER.error("Unable to process settings file", e); throw new RuntimeException("Unable to process settings file", e);