Browse Source

Better logging for settings/blockchain JSON file parsing

pull/67/head
catbref 6 years ago
parent
commit
c7123df79d
  1. 12
      src/main/java/org/qora/block/BlockChain.java
  2. 12
      src/main/java/org/qora/settings/Settings.java

12
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);

12
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);

Loading…
Cancel
Save