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

Exception when running tests under Windows 8 #919

Closed
pierre-leonard opened this issue Oct 15, 2018 · 11 comments
Closed

Exception when running tests under Windows 8 #919

pierre-leonard opened this issue Oct 15, 2018 · 11 comments

Comments

@pierre-leonard
Copy link

Hi,

I'm trying to run unit tests using testcontainers and Docker toolbox. All tests fail because of this exception:

Caused by: java.nio.file.InvalidPathException: Illegal char <"> at index 0: "C:\Program Files (x86)\Git\bin" at sun.nio.fs.WindowsPathParser.normalize(WindowsPathParser.java:182) at sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:153) at sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:77) at sun.nio.fs.WindowsPath.parse(WindowsPath.java:94) at sun.nio.fs.WindowsFileSystem.getPath(WindowsFileSystem.java:255) at java.nio.file.Paths.get(Paths.java:84) at org.testcontainers.utility.CommandLine.executableExists(CommandLine.java:67) at org.testcontainers.utility.DockerMachineClient.isInstalled(DockerMachineClient.java:53)

My bash.exe is not there anyway. But even if it was, it would throw the same exception I guess. How can I update this path?

@pierre-leonard
Copy link
Author

Solved by checking the source code. Testcontainers is actually looking for docker-machine.exe and for that, checks every directory in the path environment variable until it finds it. So '"' symbol should be removed from there. if using Eclipse, you should restart it after that.

@krmahadevan
Copy link

I stumbled into the same exact problem for someone in the team. The root cause of the problem was that there was a directory location added to the PATH variable which contained a " (double quotes in it) which was causing this problem.

@kiview
Copy link
Member

kiview commented Jul 7, 2021

On a side note, Docker Toolbox (as utilized on Windows 8) is not officially supported by Testcontainers anymore and not actively tested by us. Also see https://www.testcontainers.org/supported_docker_environment/.

@krmahadevan
Copy link

@kiview thanks for sharing that additional context. In my case we hit this problem on windows 10. The OS is a newer one but the root cause was the same.

Maybe we could consider wrapping this exception and putting in a more descriptive error message. I ask because we spent a couple of hours looking for the cause and only because of this defect we were able to identify the root cause.

@kiview
Copy link
Member

kiview commented Jul 8, 2021

I hear you, but I am not sure if Testcontainers should have additional handling for this. But I wonder, if a directory with a " is added to the PATH in a valid way, why would sun.nio.fs.WindowsPathParser.normalize() fail in this case? Is this in a way an upstream Java bug?

@krmahadevan
Copy link

@kiview - Could be.. I am not sure.. But for sure it doesnt seem to be able to handle the quotes in the path, while I dont see the problem happen in OSX.

@krmahadevan
Copy link

In org.testcontainers.utility.DockerMachineClient#isInstalled we could try and wrap

    public boolean isInstalled() {
        return executableExists(executableName);
    }

Within a try..catch and maybe give a better error message is what I was trying to check with you.

@kiview
Copy link
Member

kiview commented Jul 9, 2021

Maybe it is even better to simply log InvalidPathException and try to continue (as discussed in GoogleCloudPlatform/appengine-plugins#427). We should validate, if " is valid in a Windows path.

@krmahadevan
Copy link

@kiview - You mean that we wrap this line within a try..catch block, log the invalid path as a warning, and then continue iterating over the rest of the directories that are path of the PATH variable ?

@kiview
Copy link
Member

kiview commented Jul 12, 2021

Exactly. However, I'd still like to understand if this is something to be expected as an element in the Windows PATH, e.g. for escaping spaces. If yes, we might also assume, our way of handling the content of the Windows PATH here is too naïve:

return System.getenv("PATH").split(Pattern.quote(File.pathSeparator));

In this case, we should fix the parsing of the Windows PATH instead.

I personally feel, adding PATH elements like this is not required by Windows and seems more like bugs and wrong escaping by certain installers, e.g. certain Git versions in this case.

@padmajadav
Copy link

I found similar issue in Windows 10 and corrected Windows environment variable where I was seeing my PATH variables quoted in "". Removal of "" from Environment Variable --> path variable Fix the issue.

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

4 participants