Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

gocode-gomod and godef-gomod fails to install on multi path gopath #1966

Closed
AlexRouSg opened this issue Oct 4, 2018 · 12 comments
Closed

gocode-gomod and godef-gomod fails to install on multi path gopath #1966

AlexRouSg opened this issue Oct 4, 2018 · 12 comments

Comments

@AlexRouSg
Copy link

AlexRouSg commented Oct 4, 2018

Steps to Reproduce:

  1. Have a multi path gopath, e.g. C:\folder1;C:\folder2;
  2. Run command Go: Install/Update Tools
  3. Select all

Looks like the script is assuming gopath is a single path and blindly passing gopath around.

2 tools failed to install.

gocode-gomod:
Error: Command failed: C:\Go\bin\go.exe build -o C:\folder1;C:\folder2;\bin\gocode-gomod.exe github.com/stamblerre/gocode
go build github.com/stamblerre/gocode: mkdir C:\folder1;C:: The filename, directory name, or volume label syntax is incorrect.
go build github.com/stamblerre/gocode: mkdir C:\folder1;C:: The filename, directory name, or volume label syntax is incorrect.

godef-gomod:
Error: Command failed: C:\Go\bin\go.exe build -o C:\folder1;C:\folder2;\bin\godef-gomod.exe github.com/ianthehat/godef
go build github.com/ianthehat/godef: mkdir C:\folder1;C:: The filename, directory name, or volume label syntax is incorrect.
go build github.com/ianthehat/godef: mkdir C:\folder1;C:: The filename, directory name, or volume label syntax is incorrect.
@AlexRouSg
Copy link
Author

@godblesshugh That issue is unrelated

@godblesshugh
Copy link

@godblesshugh That issue is unrelated

sorry didn't read carefully, unrelated indeed.

@Delphier
Copy link

same issue +1

@AlexRouSg
Copy link
Author

Thought I'd tell everyone the workaround just incase no one figured it out yet. Set go.toolsGopath in the settings so it will then only have one gopath location.

@margusha
Copy link

margusha commented Oct 12, 2018

installation on mac also fails and setting go.toolsGopath did not help either. Seems the issue for me is on this line:

https://github.com/Microsoft/vscode-go/blob/4abdf8f604c720a346bf7c0910588568a6a23807/src/goInstallTools.ts#L358

getBinPath(tool) resolves to 'gocode-gomod' which is obviously wrong and throws system error "Error: spawn ENOTDIR" which causes promise to be rejected without handling the rejection and as a result nothing is installed and no error is seen on the ui.

the issue seems to be that in case getBinPath(tool) returns just a toolname (e.g. gocode-gomod) then there's no starting slash which would indicate filesystem path and causes OS level error. when I switched that line to cp.execFile('/'+tool, ....) install completed successfully (though this is not a 'production' fix obviously)

I was struggling to understand why there would be any need to start a process with a binary that does not exist yet.

@ramya-rao-a
Copy link
Contributor

ramya-rao-a commented Oct 15, 2018

@margusha I tried to repro your case and deleted the gocode-gomod binary from my Mac. When prompted to install, I got a ENOENT error (which gets handled as expected) at the place where you get ENOTDIR.

screen shot 2018-10-15 at 2 39 17 pm

the issue seems to be that in case getBinPath(tool) returns just a toolname (e.g. gocode-gomod)

This is by design. cp.execFile takes file name or path. Either works. See https://nodejs.org/api/child_process.html#child_process_child_process_execfile_file_args_options_callback

So I am unsure why you would get the ENOTDIR error..

What version of node do you have?

@ramya-rao-a
Copy link
Contributor

ramya-rao-a commented Oct 15, 2018

Others,

The fix for the multiple GOPATH issue been pushed to master and is available in the latest beta version of this extension

@ramya-rao-a
Copy link
Contributor

@margusha getBinPath returns the tool name when it cant find the absolute path to it. I've pushed a check to not to attempt to close gocode when we dont have the path to the tool beforehand

@margusha
Copy link

margusha commented Oct 16, 2018

@ramya-rao-a I was using node 10.9.0 but tried with 6.x, 8.x, 9.x and encountered the same issue.

I managed to reproduce both errors in isolation on command line.

var cp = require('child_process');
cp.execFile('noslashatthebeginning', [], {}, (err, stdin, stderr) => { console.log("error", err) });

outputs Error: spawn ENOTDIR

and if I add forward slash to the first argument like in following snippet, it will behave differently by giving ENOENT:

var cp = require('child_process');
cp.execFile('/thereisaslashathebeginning', [], {}, (err, stdin, stderr) => { console.log("error", err) });

the cp.execFile runs correctly if it finds binary file from path. e.g. cp.execFIle('node',[-v], () => {}). runs correctly.

just went over with debugger and getBinPath('gocode-gomod') returns gocode-gomod which is not a command neither a path but causes ENOTDIR which indicates there should be something on that path. which doesn't make sense.

I guess it is related to node.js itself. if I'm not mistaken, older versions of node.js child_process.spawn did not handle ENOTDIR which could lead to unhandled promise rejection but the error itself should not even happen in this case.

Can't reproduce the ENOTDIR on different machine though. something magical is going on. it is too specific issue to spend time on and investigate further but maybe it helps someone else if in the same situation.

the other way to get the installation to work is by manually installing gocode and gocode-gomod, just have to take in to account that both install under the same name and one should be named gocode-gomod

go get github.com/stamblerre/gocode // rename this one to gocode-gomod
go get github.com/mdempsky/gocode

I guess my initial whining about the failing install was premature and it is related to something specific to my environment, sorry :)

Will try out if your code change makes my computer happy

@ramya-rao-a
Copy link
Contributor

@margusha Thanks for the info! I was really curious about why I see only ENOENT and not ENOTDIR

Regardless, you are right. We shouldnt be attempting to run cp.execFile when it is clear that gocode-gomod doesnt exist. I have pushed a fix for the same

@ramya-rao-a
Copy link
Contributor

The fix for this issue is now out in the latest update to the Go extension (0.6.92)

@margusha
Copy link

It works like a charm! installs the tools correctly. thanks :)

@vscodebot vscodebot bot locked and limited conversation to collaborators Dec 1, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants