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: bad error message for local imports in module mode #47088

Open
bcmills opened this issue Jul 7, 2021 · 0 comments · May be fixed by #47516
Open

cmd/go: bad error message for local imports in module mode #47088

bcmills opened this issue Jul 7, 2021 · 0 comments · May be fixed by #47516

Comments

@bcmills
Copy link
Member

@bcmills bcmills commented Jul 7, 2021

In module mode, if an import statement refers to a relative path it is currently supposed to fail with relative import not supported:

if build.IsLocalImport(path) {
return module.Version{}, "", fmt.Errorf("relative import not supported")
}

However, we seem to be missing test coverage for that error message, and the actual error that is printed for that case is substantially different:

$ go version
go version devel go1.17-912f07504 Fri Jul 2 21:06:08 2021 +0000 linux/amd64

$ go build .
main.go:4:2: local import "./foo" in non-local package

-- foo/foo.go --
package foo
-- go.mod --
module example.com/m

go 1.17
-- main.go --
package main

import (
	_ "./foo"
)

func main() {}
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/usr/local/google/home/bcmills/.cache/go-build"
GOENV="/usr/local/google/home/bcmills/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/tmp/tmp.8tQ48Pjrac/.gopath/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/tmp/tmp.8tQ48Pjrac/.gopath"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/google/home/bcmills/sdk/gotip"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/google/home/bcmills/sdk/gotip/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="devel go1.17-912f07504 Fri Jul 2 21:06:08 2021 +0000"
GCCGO="/usr/local/google/home/bcmills/bin/gccgo"
AR="ar"
CC="gcc"
CXX="c++"
CGO_ENABLED="1"
GOMOD="/tmp/tmp.8tQ48Pjrac/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-build181655066=/tmp/go-build -gno-record-gcc-switches"

That error message comes from here:

err = ImportErrorf(path, "local import %q in non-local package", path)

which implies that the error returned by importFromModules is either not produced or not propagated as we expect.

Discovered via https://stackoverflow.com/q/68261085.

CC @matloob @jayconrod

@bcmills bcmills added this to the Backlog milestone Jul 7, 2021
@bcmills bcmills changed the title cmd/go: bad error message when cmd/go: bad error message for local imports in module mode Jul 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

1 participant