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

Invalid JSON when used with Java environment variables #65

Closed
pedrosland opened this issue Mar 25, 2015 · 5 comments
Closed

Invalid JSON when used with Java environment variables #65

pedrosland opened this issue Mar 25, 2015 · 5 comments

Comments

@pedrosland
Copy link

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.

@jzaefferer
Copy link
Contributor

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.

@pedrosland
Copy link
Author

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 :)

@jawshooah
Copy link
Contributor

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

@jzaefferer
Copy link
Contributor

Closing due to inactivity / lack of interest.

@nigelmegitt
Copy link

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

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