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: improve error message for missing dependencies when building files from another module #45014

Open
FiloSottile opened this issue Mar 15, 2021 · 3 comments
Labels
modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@FiloSottile
Copy link
Contributor

Let's say I have a module, foo, with a main.go file with a dependency on filippo.io/edwards25519. If I run or build main.go from inside foo, everything goes well.

If I run it or build it from outside the module, I get

$ go run foo/main.go
foo/main.go:3:8: no required module provides package filippo.io/edwards25519: working directory is not part of a module

If I run it or build it from inside a different module, I get

$ go run ../foo/main.go
../foo/main.go:3:8: no required module provides package filippo.io/edwards25519; to add it:
	go get filippo.io/edwards25519

In both cases, the error message could have noticed that main.go is inside a (different) module, and added something like

note: the file is in a module that is not active, to activate it:
	cd .../foo

(go run and go build with .go files are a constant source of confusion, got way less useful with modules because one can't just run arbitrary files as scripts from anywhere, and should IMHO be deprecated, but while we support them we should try to make them less painful.)

@cherrymui cherrymui added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Mar 15, 2021
@cherrymui cherrymui added this to the Backlog milestone Mar 15, 2021
@cherrymui
Copy link
Member

cc @bcmills @jayconrod @matloob

@bcmills bcmills changed the title cmd/go: improve error message for building files from another module cmd/go: improve error message for missing dependencies when building files from another module Mar 15, 2021
@bcmills bcmills added NeedsFix The path to resolution is known, but the work has not been done. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. and removed NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. NeedsFix The path to resolution is known, but the work has not been done. labels Mar 15, 2021
@bcmills
Copy link
Contributor

bcmills commented Mar 15, 2021

The not active terminology seems a bit confusing too. Perhaps:

note: foo/main.go is in a module rooted at ./foo; to use its dependencies, first change to a directory within that module:
	cd ../foo

Hmm, but if we're already in some other module, it's not obvious whether the right solution is to cd into that directory (using its dependencies instead of those of the current module), or to add replace and require directives to add it as a dependency of the current module.

@bcmills
Copy link
Contributor

bcmills commented Mar 15, 2021

(If we're currently not in any module at all, I think it would be reasonable to suggest the cd command.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

3 participants