Permalink
Browse files

Fix bug where validation errors don't give any details

  • Loading branch information...
ndw committed Mar 4, 2018
1 parent cced330 commit f45721d27ee865f77e3d6ea7da0180f937402497
@@ -105,7 +105,7 @@ public void run() throws SaxonApiException {
boolean checkIdRefs = getOption(_dtd_id_idref_warnings,false);
boolean dtdAugment = getOption(_dtd_attribute_values,false);
ErrorHandler eh = new RNGErrorHandler();
RNGErrorHandler eh = new RNGErrorHandler();
PropertyMapBuilder properties = new PropertyMapBuilder();
properties.put(ValidateProperty.ERROR_HANDLER, eh);
properties.put(ValidateProperty.URI_RESOLVER, runtime.getResolver());
@@ -156,15 +156,15 @@ public void run() throws SaxonApiException {
InputSource din = S9apiUtils.xdmToInputSource(runtime, doc);
if (!driver.validate(din)) {
if (assertValid) {
throw XProcException.stepError(53);
throw XProcException.stepError(53, eh.getErr());
}
}
} else {
throw new XProcException(step.getNode(), "Error loading schema");
}
} catch (SAXParseException e) {
if (assertValid) {
throw XProcException.stepError(53);
throw XProcException.stepError(53, e);
}
} catch (SAXException e) {
throw new XProcException("SAX Exception", e);
@@ -188,6 +188,10 @@ private String compactSchema(XdmNode doc) {
class RNGErrorHandler implements ErrorHandler {
SAXParseException err = null;
public SAXParseException getErr() {
return err;
}
public void fatalError(SAXParseException e) throws SAXException {
error(e);
}
@@ -213,7 +217,7 @@ public void error(SAXParseException e) throws SAXException {
treeWriter.endDocument();
step.reportError(treeWriter.getResult());
if (err != null) {
if (err == null) {
err = e;
}
}
@@ -59,7 +59,7 @@
private WritablePipe result = null;
private URI docBaseURI = null;
/* Creates a new instance of Delete */
/* Creates a new instance of ValidateWithRNG */
public ValidateWithRNG(XProcRuntime runtime, XAtomicStep step) {
super(runtime,step);
}
@@ -102,7 +102,7 @@ public void run() throws SaxonApiException {
doc = source.read();
docBaseURI = doc.getBaseURI();
if (verifier != null && !verifier.verify(S9apiUtils.xdmToInputSource(runtime, doc))) {
if (!verifier.verify(S9apiUtils.xdmToInputSource(runtime, doc))) {
throw new XProcException(XProcException.err_E0001, "Document is not valid");
}
@@ -113,7 +113,7 @@ public void run() throws SaxonApiException {
} catch (SAXException sx) {
// Assume the only error is validity failed?
if (getOption(_assert_valid,false)) {
throw XProcException.stepError(53);
throw XProcException.stepError(53, sx);
}
result.write(doc);
} catch (IOException ioe) {

0 comments on commit f45721d

Please sign in to comment.