validator/grunt-html

Invalid JSON when used with Java environment variables

pedrosland opened this issue · 5 comments

Our builds are done in a Docker container and this has several environment variables set including JAVA_TOOL_OPTIONS. Sadly this causes Java to print a message on stderr. When grunt-html reads from stderr and tries to parse the JSON, it throws a "helpful" exception like Unexpected token P without a stack trace. It seems that this Java notice can't be disabled.

You can test by running JAVA_TOOL_OPTIONS="-Dfile.encoding=UTF8" java in your shell. You should see Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF8 followed by the help. There is an openjdk issue for this https://bugs.openjdk.java.net/browse/JDK-8039152.

What would be nice is to provide better error handling so that a user can easily tell that the Java validator isn't returning valid JSON. I think that this is probably worth doing. I can make a PR if you like.

We could also test for this message and strip it before parsing but I'm not sure that you want a hack for something this although it should help it be more universal.

I have worked around this by removing this environment variable from process.env and this prevents it being passed to spawned processes too. With this fix, I have no problems so feel free to just close this if you like.

I recently converted one of our projects to use grunt-html instead of grunt-validate-html. Its working great - thanks.

What would be nice is to provide better error handling so that a user can easily tell that the Java validator isn't returning valid JSON. I think that this is probably worth doing. I can make a PR if you like.

That sounds pretty good, since this isn't the first time the javadetect module has failed us. Providing better error messages is always a good first step.

I have worked around this by removing this environment variable from process.env and this prevents it being passed to spawned processes too. With this fix, I have no problems so feel free to just close this if you like.

Did you modify this module for that fix? Or is in your Gruntfile or some other place? The former would be bad, the latter seems okay.

What would be nice is to provide better error handling so that a user can easily tell that the Java validator isn't returning valid JSON. I think that this is probably worth doing. I can make a PR if you like.

That sounds pretty good, since this isn't the first time the javadetect module has failed us. Providing better error messages is always a good first step.

I'll open a PR in a couple of days when I get time.

I have worked around this by removing this environment variable from process.env and this prevents it being passed to spawned processes too. With this fix, I have no problems so feel free to just close this if you like.

Did you modify this module for that fix? Or is in your Gruntfile or some other place? The former would be bad, the latter seems okay.

I modified my Gruntfile to check for process.env.JAVA_TOOL_OPTIONS and delete it if it exists. I didn't modify your library :)

For reference, the error can be reproduced as follows:

$ JAVA_TOOL_OPTIONS="-Dfile.encoding=UTF8" grunt htmllint:valid
Running "htmllint:valid" (htmllint) task
Fatal error: Unexpected token P

Closing due to inactivity / lack of interest.

This is still causing issues - would really appreciate a fix.