validator/grunt-html

Fatal error: Unexpected token E

burgaard opened this issue · 3 comments

I was using grunt-html in a project and it worked fine for a while. Then the htmllint task began to fail with "Fatal error: Unexpected token E".

This issue is not a duplicate of #65 "Fatal error: Unexpected token P", because in my case, I don't have JAVA_TOOL_OPTIONS defined in my environment.

Running grunt with --stack resulted in

SyntaxError: Unexpected token E
    at Object.parse (native)
    at /Users/kim/Projects/sandboot/node_modules/grunt-html/lib/htmllint.js:46:25
    at ChildProcess.exithandler (child_process.js:210:5)
    at emitTwo (events.js:87:13)
    at ChildProcess.emit (events.js:172:7)
    at maybeClose (internal/child_process.js:817:16)
    at Socket.<anonymous> (internal/child_process.js:319:11)
    at emitOne (events.js:77:13)
    at Socket.emit (events.js:169:7)
    at Pipe._onclose (net.js:469:12)

So I added console.error(stderr); to grunt-html/lib/htmllint.js before line 46 and got

Exception in thread "main" java.lang.NoClassDefFoundError: nu/validator/datatype/CdoCdcPair
    at nu.validator.datatype.Html5DatatypeLibrary.createDatatype(Html5DatatypeLibrary.java:152)
    at nu.validator.spec.html5.Html5AttributeDatatypeBuilder.endElement(Html5AttributeDatatypeBuilder.java:155)
    at nu.validator.saxtree.TreeParser.endElement(TreeParser.java:132)
    at nu.validator.saxtree.Element.revisit(Element.java:110)
    at nu.validator.saxtree.TreeParser.parse(TreeParser.java:95)
    at nu.validator.htmlparser.sax.HtmlParser.parse(HtmlParser.java:428)
    at nu.validator.spec.html5.Html5AttributeDatatypeBuilder.parseSyntaxDescriptions(Html5AttributeDatatypeBuilder.java:75)
    at nu.validator.messages.MessageEmitterAdapter.<clinit>(MessageEmitterAdapter.java:289)
    at nu.validator.client.SimpleCommandLineValidator.setErrorHandler(SimpleCommandLineValidator.java:326)
    at nu.validator.client.SimpleCommandLineValidator.setup(SimpleCommandLineValidator.java:190)
    at nu.validator.client.SimpleCommandLineValidator.main(SimpleCommandLineValidator.java:179)
Caused by: java.lang.ClassNotFoundException: nu.validator.datatype.CdoCdcPair
    at java.net.URLClassLoader$1.run(URLClassLoader.java:199)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    ... 11 more
Caused by: java.util.zip.ZipException: invalid LOC header (bad signature)
    at java.util.zip.ZipFile.read(Native Method)
    at java.util.zip.ZipFile.access$1200(ZipFile.java:31)
    at java.util.zip.ZipFile$ZipFileInputStream.read(ZipFile.java:461)
    at java.util.zip.ZipFile$1.fill(ZipFile.java:244)
    at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:141)
    at sun.misc.Resource.getBytes(Resource.java:108)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:257)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
    ... 16 more

Then I checked vnu.jar embedded with grunt-html to see if it was corrupted:

$ java -jar vnu.jar
Usage:

    java -jar vnu.jar [--errors-only] [--no-stream]
         [--format gnu|xml|json|text] [--help] [--html]
         [--skip-non-html] [--verbose] [--version] FILES

    java -cp vnu.jar nu.validator.servlet.Main 8888

    java -cp vnu.jar nu.validator.client.HttpClient FILES

For detailed usage information, use "java -jar vnu.jar --help" or see:

  http://validator.github.io/

To read from stdin, use "-" as the filename, like this: "java -jar vnu.jar - ".
Mac-10ddb1d127ad:grunt-html kim$ java -jar vnu.jar 
Usage:

    java -jar vnu.jar [--errors-only] [--no-stream]
         [--format gnu|xml|json|text] [--help] [--html]
         [--skip-non-html] [--verbose] [--version] FILES

    java -cp vnu.jar nu.validator.servlet.Main 8888

    java -cp vnu.jar nu.validator.client.HttpClient FILES

For detailed usage information, use "java -jar vnu.jar --help" or see:

  http://validator.github.io/

To read from stdin, use "-" as the filename, like this: "java -jar vnu.jar - ".

In order to move on, I then deleted node_modules/grunt-html and ran npm install to reinstall it.

Unfortunately, that worked. So, somehow I had a corrupted Jar file which may or may not have been vnu.jar and I have no idea how the corruption happened.

Not sure this helps at all, but hopefully it'll help other people who run into the same error message.

Thanks to #81 this error will be a bit "easier" to detect, but without any way to reproduce it, I don't think there's anything I can do here.

Well, you closed #81. #67 doesn't look like it's moving forward and in the meanwhile leaving users with 'Fatal error: Unexpected token ...' is not particularly helpful...

I closed with a commit: e873539

I edited the commit message to reference the pull request, that's why its not showing the PR as merged.