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 · 7 comments
Open
Labels
modules NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@hyangah
Copy link
Contributor

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
Contributor

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)

@bcmills bcmills added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Feb 12, 2019
@hyangah
Copy link
Contributor Author

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

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
Contributor

bcmills commented Feb 12, 2019

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

@jayconrod
Copy link
Contributor

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?

@jayconrod jayconrod added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Jun 5, 2019
@bcmills bcmills added this to the Go1.14 milestone Jun 7, 2019
@bcmills
Copy link
Contributor

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
@gopherbot
Copy link

Change https://go.dev/cl/585055 mentions this issue: cmd/go: return error when directory has no go.mod in module mode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
modules NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants