Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong/Misleading error report and error handling when reading erroneous groups #190

Open
g0dkar opened this issue Jul 29, 2014 · 1 comment

Comments

@g0dkar
Copy link

g0dkar commented Jul 29, 2014

Hi! I was developing something using wro4j and noted that it started giving me this exception:

Jul 29, 2014 12:37:16 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [default] in context with path [] threw exception [Filter execution threw an exception] with root cause
java.lang.ClassNotFoundException: groovy.lang.GroovyShell
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
    at ro.isdc.wro.extensions.model.factory.GroovyModelFactory.create(GroovyModelFactory.java:64)
    at ro.isdc.wro.extensions.model.factory.GroovyModelFactory.create(GroovyModelFactory.java:42)
    at ro.isdc.wro.model.factory.LazyWroModelFactoryDecorator.create(LazyWroModelFactoryDecorator.java:28)
    [...]

After a while trying to figure it out, I turned on WRO's debug option and found out the real error was this one:

00:37:16,388 DEBUG [SmartWroModelFactory] [FAIL] creating model... will try another factory: {}
org.xml.sax.SAXParseException; cvc-id.2: There are multiple occurrences of ID value 'user-list'.
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:203)
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:134)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:437)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:368)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:325)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator$XSIErrorReporter.reportError(XMLSchemaValidator.java:458)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.reportSchemaError(XMLSchemaValidator.java:3237)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.processOneAttribute(XMLSchemaValidator.java:2832)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.processAttributes(XMLSchemaValidator.java:2769)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:2056)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(XMLSchemaValidator.java:746)
    at com.sun.org.apache.xerces.internal.jaxp.validation.DOMValidatorHelper.beginNode(DOMValidatorHelper.java:277)
    at com.sun.org.apache.xerces.internal.jaxp.validation.DOMValidatorHelper.validate(DOMValidatorHelper.java:244)
    at com.sun.org.apache.xerces.internal.jaxp.validation.DOMValidatorHelper.validate(DOMValidatorHelper.java:190)
    at com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorImpl.validate(ValidatorImpl.java:109)
    at javax.xml.validation.Validator.validate(Validator.java:124)
    at ro.isdc.wro.model.factory.XmlModelFactory.validate(XmlModelFactory.java:215)
    at ro.isdc.wro.model.factory.XmlModelFactory.createDocument(XmlModelFactory.java:199)
    at ro.isdc.wro.model.factory.XmlModelFactory.create(XmlModelFactory.java:167)
    at ro.isdc.wro.model.factory.XmlModelFactory.create(XmlModelFactory.java:56)
    [...]

Meaning the XML itself is invalid, having two <group> tags with the same name - but the error thrown by wro was about not being able to find Groovy o_O

It doesn't fail there because at SmartWroModelFactory:195 you expect a WroRuntimeException, which in turn is never expected/thrown at XmlModelFactory:215. God (and prob you, hehe) knows why this ends up with a "GroovyShell not found" exception :P

A quick solution would be to change it to:

try {
    schema.newValidator().validate(new DOMSource(document));
} catch (SAXParseException spe) {
    throw new WroRuntimeException("Invalid wro.xml, please check it for errors like repeated ID's, malformed XML or something like that", spe);
}

Last but not least, congrats for maintaining this amazing project! It really grown into something incredibly useful!

@alexo
Copy link
Owner

alexo commented Jul 30, 2014

Yeah, the SmartWroModelFactory is not so smart after all :)... I would gladly deprecate this feature and would keep things simpler: less is more. Some of the features cause more problems than the benefit they bring....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants