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: confusing error when trying to build a package conflicting with an std import path #32576

Closed
loburm opened this issue Jun 12, 2019 · 2 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@loburm
Copy link

loburm commented Jun 12, 2019

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

go version go1.12.5 linux/amd64

Does this issue reproduce with the latest release?

Yes. Latest version of Go without this issue is 1.7.

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

GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/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=""
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-build789582237=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Steps to reproduce:

  1. Create file test.go with content:
package test

import (
	"fmt"
	gce "cloud.google.com/go/compute/metadata"
)

func main(){
	if gce.OnGCE() {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}
  1. Create vendor package:
    $ dep init

  2. Create Docker file:

FROM golang:1.12

RUN mkdir -p $GOPATH/src/plugin
ADD . $GOPATH/src/plugin

WORKDIR $GOPATH/src/plugin
RUN go build .
  1. Build image:
    docker build .

What did you expect to see?

App should be built.

What did you see instead?

unexpected directory layout:
import path: cloud.google.com/go/compute/metadata
root: /go/src
dir: /go/src/plugin/vendor/cloud.google.com/go/compute/metadata
expand root: /go/src
expand dir: /go/src/plugin/vendor/cloud.google.com/go/compute/metadata
separator: /

Looks that for some reason 'plugin' name is reserved. If in Docker file I replace it by any other word, then it works.

I'm not against reserved package name, but in such case error message should be useful. In this case I have spent whole day on debugging this issue.

@mvdan
Copy link
Member

mvdan commented Jun 12, 2019

Like you said, import paths without a top-level domain are reserved by the standard library. That is, you should use foo.com/bar, not bar.

It's also fine if you don't have a real public URL or domain for this. You can use dummy domains like dev.tld/bar.

I'll leave it to @bcmills to give input regarding a better error message; I couldn't find an existing issue for this.

@mvdan mvdan changed the title $GOPATH/src/plugin is a specially reserved package starting from 1.8 cmd/go: confusing error when trying to build a package conflicting with an std import path Jun 12, 2019
@mvdan mvdan added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jun 12, 2019
@bcmills
Copy link
Contributor

bcmills commented Jun 13, 2019

Given that this only affects GOPATH mode, and only affects paths that conflict with packages that actually exist in the standard library, I don't think it's worth the effort to fix (and test and review the fix) at this point.

If the error is still confusing in module mode, please open a new issue (ideally with steps to reproduce that do not require running docker or dep).

@bcmills bcmills closed this as completed Jun 13, 2019
@golang golang locked and limited conversation to collaborators Jun 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants