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

cmd/go: 'go list -m -json' in an empty directory returns cryptic output #30136

Open
hyangah opened this issue Feb 8, 2019 · 6 comments
Open

cmd/go: 'go list -m -json' in an empty directory returns cryptic output #30136

hyangah opened this issue Feb 8, 2019 · 6 comments
Labels
Milestone

Comments

@hyangah
Copy link
Contributor

@hyangah hyangah commented Feb 8, 2019

$ go version
go version devel +56c9f8e8cf linux/amd64

$ cd $(mktemp -d)
$ GO111MODULE=on go list -m -json 
{
	"Path": "command-line-arguments",
	"Main": true
}
@hyangah hyangah added the modules label Feb 8, 2019
@bcmills
Copy link
Member

@bcmills bcmills commented Feb 12, 2019

This output is correct, if a bit strange: if you run a go command outside of any module, the effective module name for the resulting artifacts is command-line-arguments, and because you passed the -m flag it doesn't need a module path to resolve the effective import path of the current directory (and therefore doesn't error on the fact that there is no such module path).

I suppose that we could add some sort of special case, but I can't think of one would simplify this case more than it complicates others. Any concrete suggestions?

(CC @jayconrod)

@hyangah
Copy link
Contributor Author

@hyangah hyangah commented Feb 12, 2019

Without -m, the error message is more comprehensive.
I don't know how complex it will be to handle this special case.

$ GO111MODULE=on go list -json
go: cannot find main module; see 'go help modules'
@jayconrod
Copy link
Contributor

@jayconrod jayconrod commented Feb 12, 2019

Is there anything go list -m can do without a module root? The arguments are all module paths or queries, and those are only meaningful if we can generate the build list, which is going to be empty if there's no go.mod and no source files.

There's a branch in go list to handle -m behavior. I think we can just add a call to modload.ModRoot in there. That would print the cannot find main module message.

@bcmills
Copy link
Member

@bcmills bcmills commented Feb 12, 2019

go list -m --versions is very useful without a module root.

@jayconrod
Copy link
Contributor

@jayconrod jayconrod commented Feb 13, 2019

True, so is -u. And positional query arguments work, too.

So if we added a special case for this, it would just be for go list -m. No positional arguments. No -u, -versions or other options that affect semantics (-json would be okay though). The logic would just be in internal/list/list.go though; module and package loading infrastructure would be unaffected.

@hyangah WDYT? Worth adding?

@bcmills bcmills added this to the Go1.14 milestone Jun 7, 2019
@bcmills
Copy link
Member

@bcmills bcmills commented Jul 9, 2019

Depending on the outcome of #32027, this issue may become moot.

@rsc rsc modified the milestones: Go1.14, Backlog Oct 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.