Skip to content

cmd/go: improve error message for missing dependencies when building files from another module #45014

Open
@FiloSottile

Description

@FiloSottile

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    BadErrorMessageIssues related compiler error messages that should be better.GoCommandcmd/goNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.modules

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions