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

go/build: better explanation for "cannot find package" #4079

Closed
robpike opened this issue Sep 13, 2012 · 8 comments
Closed

go/build: better explanation for "cannot find package" #4079

robpike opened this issue Sep 13, 2012 · 8 comments
Labels
FrozenDueToAge Suggested Issues that may be good for new contributors looking for work to do.
Milestone

Comments

@robpike
Copy link
Contributor

robpike commented Sep 13, 2012

In Import in go/build/build.go, the error message "cannot find package" could
be more helpful. It's a stumbling block for beginners.  It might even help just to
change it to:

cannot find package on $GOROOT or $GOPATH

cannot find package on $GOROOT(="...") or $GOPATH(="...")

I'm sure more could be done. The point is we know much about why it failed that we don't
tell the user.
@rsc
Copy link
Contributor

rsc commented Oct 6, 2012

Comment 1:

Labels changed: added go1.1.

@davecheney
Copy link
Contributor

Comment 2:

I'd like to take a stab at this as I have a strong incentive to make this better for
people on the IRC channel.
Here are some suggestions i've played around with
% go build foo/quxx
can't load package: package foo/quxx: import "foo/quxx": cannot find package in
$GOROOT="/home/dfc/go" or $GOPATH="/home/dfc"
This is the original suggestion, but I think it lacks something as GOPATH for example
doesn't actually mention /home/dfc/src, where src is the crucial bit that trips up a lot
of people.
% go build foo/quxx
can't load package: package foo/quxx: import "foo/quxx": cannot find package in
["/home/dfc/go/src/pkg" "/home/dfc/src"]
This is a different version using ctxt.SrcDirs(), which gives the canonical list of
paths that would be searched for the package, but doesn't explain how they are
discovered, and in the case that GOPATH was not set, would only list the GOROOT derived,
/home/dfc/go/src/pkg. This has the downside of leading users into trying to set GOPATH
somewhere inside GOROOT, or using sudo.

Owner changed to @davecheney.

@rsc
Copy link
Contributor

rsc commented Dec 9, 2012

Comment 3:

It's fine to make the error multiple lines:
cannot find "foo/quux" in any of:
    /home/rsc/g/go/src/pkg/foo/quux (from $GOROOT)
    /home/rsc/goroot1/src/foo/quux (from $GOPATH)
    /home/rsc/goroot2/src/foo/quux
cannot find "foo/quux" in any of:
    /home/rsc/g/go/src/pkg/foo/quux (from $GOROOT)
    ($GOPATH not set)

@davecheney
Copy link
Contributor

Comment 4:

Can do.

@rsc
Copy link
Contributor

rsc commented Dec 10, 2012

Comment 5:

Labels changed: added size-m.

@rsc
Copy link
Contributor

rsc commented Dec 10, 2012

Comment 6:

Labels changed: added suggested.

@davecheney
Copy link
Contributor

Comment 7:

https://golang.org/cl/6899057

Status changed to Started.

@davecheney
Copy link
Contributor

Comment 8:

This issue was closed by revision 11d96dd.

Status changed to Fixed.

@robpike robpike added fixed Suggested Issues that may be good for new contributors looking for work to do. labels Dec 12, 2012
@rsc rsc added this to the Go1.1 milestone Apr 14, 2015
@rsc rsc removed the go1.1 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge Suggested Issues that may be good for new contributors looking for work to do.
Projects
None yet
Development

No branches or pull requests

4 participants