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: command with file with wrong package silently fails to build #3389

Closed
alberts opened this issue Mar 25, 2012 · 11 comments
Closed

cmd/go: command with file with wrong package silently fails to build #3389

alberts opened this issue Mar 25, 2012 · 11 comments
Labels
FrozenDueToAge Suggested Issues that may be good for new contributors looking for work to do.
Milestone

Comments

@alberts
Copy link
Contributor

alberts commented Mar 25, 2012

What steps will reproduce the problem?

tree:

src/cmd/bar/bork.go
src/cmd/bar/main.go

$ cat src/cmd/bar/bork.go
package bork

$ cat src/cmd/bar/main.go
package main
func main() {}

What is the expected output?

some kind of build error

What do you see instead?

$ rm -rf bin pkg; GOPATH=`pwd` go install -v ./...
warning: "./..." matched no packages

$ rm -rf bin pkg; GOPATH=`pwd` go install -v cmd/bar
can't load package: package cmd/bar: open /path/to/go/src/cmd/bar: no such file or
directory

Which compiler are you using (5g, 6g, 8g, gccgo)?

6g

Which operating system are you using?

linux

Which revision are you using?  (hg identify)

go version weekly.2012-03-22 +ee5c7588cb7f

Please provide any additional information below.

I encountered this error while moving some package code into a command  to reduce the
code for another bug report. I forgot to update all the package lines, and my command
"disappeared".
@robpike
Copy link
Contributor

robpike commented Mar 25, 2012

Comment 1:

Labels changed: added priority-go1, removed priority-triage.

Owner changed to @rsc.

Status changed to Accepted.

@minux
Copy link
Member

minux commented Mar 26, 2012

Comment 2:

Another somewhat related problem is go run/build _file.go, which gives rather confusing
error message:
$ go run _file.go
package : no Go source files in /Users/minux/go/go.hg/src
$ go build _file.go
can't load package: package : no Go source files in /Users/minux/go/go.hg/src

@rsc
Copy link
Contributor

rsc commented Mar 26, 2012

Comment 3:

What's the silent part?
Both commands print errors.
"cmd/" is a special prefix reserved by Go.
Your import paths should begin with a unique
name of your own, like fullung/cmd/foo.
Russ

@alberts
Copy link
Contributor Author

alberts commented Mar 26, 2012

Comment 4:

In issue #3390 I asked: "Just to check, is it okay to use stuff under cmd? e.g.
src/cmd/foo? Or is the whole cmd/* reserved? If it is, an error might be better than
having it mostly work."
Based on Russ's comment here, it seems the answer is that cmd/* is reserved if you are
in a GOROOT project. Maybe the go tool shouldn't build anything under any GOPATH's
src/cmd directory then? I can see other people making the same mistake as we have.
src/pkg sorted itself out, because there your import path would be pkg/foo, which no-one
wants.

@alberts
Copy link
Contributor Author

alberts commented Mar 26, 2012

Comment 5:

Silent was the wrong word. The confusing thing was that this doesn't work:
$ rm -rf bin pkg; GOPATH=`pwd` go install -v cmd/bar
can't load package: package cmd/bar: open /path/to/go/src/cmd/bar: no such file or
directory
but this does work:
$ rm -rf bin pkg; GOPATH=`pwd` go install -v cmd/foo/bar
It's much less confusing when you know that cmd/* is kind of reserved and that cmd/*/*
is "less" reserved.

@rsc
Copy link
Contributor

rsc commented Mar 26, 2012

Comment 6:

Labels changed: added priority-later, removed priority-go1.

@rsc
Copy link
Contributor

rsc commented Mar 26, 2012

Comment 7:

Thanks for the clarification.  I'm happy to fix this after Go 1.

@rsc
Copy link
Contributor

rsc commented Sep 12, 2012

Comment 8:

Labels changed: added go1.1.

@rsc
Copy link
Contributor

rsc commented Dec 10, 2012

Comment 9:

Labels changed: added size-m.

@rsc
Copy link
Contributor

rsc commented Dec 10, 2012

Comment 10:

Labels changed: added suggested.

@rsc
Copy link
Contributor

rsc commented Jan 31, 2013

Comment 11:

This issue was closed by revision 8b6534b.

Status changed to Fixed.

@alberts alberts added fixed Suggested Issues that may be good for new contributors looking for work to do. labels Jan 31, 2013
@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
@rsc rsc removed their assignment Jun 22, 2022
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

5 participants