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 package not found? #32096

Closed
thatreguy opened this issue May 17, 2019 · 4 comments
Closed

cmd/go: improve error message for package not found? #32096

thatreguy opened this issue May 17, 2019 · 4 comments

Comments

@thatreguy
Copy link

@thatreguy thatreguy commented May 17, 2019

What version of Go are you using (go version)?

$ go version
1.12.4

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

Ubuntu 16.04.6/amd64

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/root/.go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/root/.go/src/github.com/firebase/firebase-admin-go/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build012231754=/tmp/go-build -gno-record-gcc-switches"

What did you do?

The following is my tree:
snippets/
├── constants
│   └── constants.go
├── libs
│   ├── auth.go
│   ├── db.go
│   ├── init.go
│   ├── messaging.go
│   └── storage.go
└── snippets.go
I was trying to import constants from snippets.go:

cat snippets.go

package main
import (
	"snippets/constants"
)
.
.
.

And did:
go build -x -v

What did you expect to see?

No error or verbose output from go build

What did you see instead?

Quite unhelpful output:
build firebase.google.com/go/snippets: cannot load snippets/constants: cannot find module providing package snippets/constants

Now for whatever reason my import might have failed, I can understand that. But I would at least like a detailed explanation from go build. (In fact, the same is true to go get, go run etc.)

@FiloSottile

This comment has been minimized.

Copy link
Member

@FiloSottile FiloSottile commented May 17, 2019

I am guessing your module here is called firebase.google.com/go/snippets, not snippets, so the import should have been firebase.google.com/go/snippets/constants. Not sure how go build could give a better error message here without guessing.

/cc @bcmills

@FiloSottile FiloSottile added this to the Unplanned milestone May 17, 2019
@FiloSottile FiloSottile changed the title Provide more verbose output to go build cmd/go: improve error message for package not found? May 17, 2019
@jayconrod

This comment has been minimized.

Copy link
Contributor

@jayconrod jayconrod commented May 30, 2019

@thatreguy You said your tree contains a directory snippets/constants. Where is this directory in relation to /root/.go/src/github.com/firebase/firebase-admin-go/go.mod? How was it created?

This is not something that would work in module mode: the Go command won't search local directories for imports outside of the main module. This worked for manually created GOPATH directories, but I'm not sure we can provide good diagnostics for that case.

@bcmills

This comment has been minimized.

Copy link
Member

@bcmills bcmills commented May 31, 2019

For the particular case where the import path doesn't start with a leading dot, there is no way such a module can exist without using a replace directive, so we can at least use that as a signal for a better error message.

@bcmills

This comment has been minimized.

Copy link
Member

@bcmills bcmills commented May 31, 2019

Duplicate of #30723

@bcmills bcmills marked this as a duplicate of #30723 May 31, 2019
@bcmills bcmills closed this May 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.