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: go list -json -e does not store location for invalid import path #69334

Open
aykevl opened this issue Sep 7, 2024 · 3 comments
Open
Assignees
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@aykevl
Copy link

aykevl commented Sep 7, 2024

Go version

go version go1.23.1 linux/arm64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/home/ayke/.cache/go-build'
GOENV='/home/ayke/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/ayke/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/ayke'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go1.23.1'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go1.23.1/pkg/tool/linux_arm64'
GOVCS=''
GOVERSION='go1.23.1'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/ayke/.config/go/telemetry'
GCCGO='gccgo'
GOARM64='v8.0'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3054841504=/tmp/go-build -gno-record-gcc-switches'

What did you do?

I have the following invalid Go file

package main

import _ "#"

func main() {
}

I ran go list -json -e importpath.go on it, to see the loader error.

What did you see happen?

The JSON contains this part:

        "Error": {
                "ImportStack": [],
                "Pos": "",
                "Err": "/home/ayke/tmp/importpath.go:3:8: invalid import path: #"
        }

That's an error, of course, but the Pos field is not set even though go list clearly knows the source location (it's stored in the error message itself).

What did you expect to see?

I expected an output like this:

        "Error": {
                "ImportStack": [],
                "Pos": "importpath.go:3:8",
                "Err": "invalid import path: #"
        }

That is, the position information should be in Pos and the path should be relative and not absolute. For example, when setting the import path to one that doesn't exist, the error looks like this:

        "Error": {
                "ImportStack": [
                        "command-line-arguments"
                ],
                "Pos": "importpath.go:3:8",
                "Err": "no required module provides package foo.bar: go.mod file not found in current directory or any parent directory; see 'go help modules'"
        }
@aykevl
Copy link
Author

aykevl commented Sep 7, 2024

Interestingly, @gabyhelp didn't show exact duplicates but does show this bug has been around for a while: it's also visible in #28491.

@timothy-king timothy-king added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 9, 2024
@timothy-king
Copy link
Contributor

CC @matloob, @samthanawalla.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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