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

Comments

@FiloSottile
Copy link
Member

@FiloSottile FiloSottile commented Mar 15, 2021

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 this to the Backlog milestone Mar 15, 2021
@cherrymui
Copy link
Contributor

@cherrymui cherrymui commented Mar 15, 2021

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

@bcmills 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
Member

@bcmills 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.)

@bcmills bcmills added the modules label Mar 15, 2021
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
3 participants