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 · 5 comments

Comments

Projects
None yet
3 participants
@hyangah
Copy link
Contributor

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

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link
Contributor Author

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

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link
Member

commented Feb 12, 2019

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

@jayconrod

This comment has been minimized.

Copy link
Contributor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.