Skip to content

cmd/go: mismatched line number and import path in error messages #72896

Description

@tigarmo

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

$ go version
go version go1.24.1 linux/amd64

Does this issue reproduce with the latest release?

Yes (this is the latest release at time of writing)

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

go env Output
$ go env
AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/home/tiago/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/tiago/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3848929413=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/home/tiago/Projects/go/work-repro3/hello/go.mod'
GOMODCACHE='/home/tiago/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/tiago/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/snap/go/10866'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/tiago/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/snap/go/10866/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.24.1'
GOWORK='/home/tiago/Projects/go/work-repro3/go.work'
PKG_CONFIG='pkg-config'
uname -sr: Linux 6.8.0-52-generic
Distributor ID:	Ubuntu
Description:	Ubuntu 22.04.5 LTS
Release:	22.04
Codename:	jammy
/lib/x86_64-linux-gnu/libc.so.6: GNU C Library (Ubuntu GLIBC 2.35-0ubuntu3.9) stable release version 2.35.
gdb --version: GNU gdb (Ubuntu 12.1-0ubuntu1~22.04.2) 12.1

What did you do?

I'm attempting to use go workspaces with GOPROXY=off to ensure I have all required sources locally. In the middle of this work, I have a single module and a workspace with the following local structure:

$ find .
.
./hello
./hello/go.mod
./hello/go.sum
./hello/hello.go
./go.work

go.work:

go 1.24.1

use ./hello

hello/go.mod:

module example.com/hello

go 1.24.1

require (
        golang.org/x/crypto v0.36.0
        golang.org/x/net v0.21.0
)

require golang.org/x/text v0.23.0 // indirect

hello/go.sum

golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34=
golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc=
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY=
golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4=

hello/hello.go

package main

import (
        "fmt"

        "golang.org/x/crypto/acme/autocert"
        "golang.org/x/net/html/charset"
)

func main() {
        fmt.Println(autocert.DefaultACMEDirectory)
        _, name := charset.Lookup("ble")
        fmt.Println("Lookup: ", name)
}

Then I run GOPROXY="off" go build hello.go from the hello directory.

What did you expect to see?

I expected error messages related to golang.org/x/crypto and golang.org/x/net being unavailable because they are not in the workspace and can't be found/downloaded because of GOPROXY=off.

What did you see instead?

This is the error output:

hello.go:6:2: golang.org/x/crypto@v0.36.0: module lookup disabled by GOPROXY=off
hello.go:7:2: golang.org/x/crypto@v0.36.0: module lookup disabled by GOPROXY=off

The first line is correct, but the second line in the error output (hello.go:7:2: golang.org/x/crypto@v0.36.0: module lookup disabled by GOPROXY=off), refers to line 7 on the source, which is the "golang.org/x/net/html/charset" import on the file listed above. The surprising behavior is that the import is for golang.org/x/net but the error message says it's for golang.org/x/crypto.

Additionally, when I run the command with JSON output (GOPROXY="off" go build -json hello.go) I get the same messages in the "Output" keys but the right paths in "ImportPath":

$ GOPROXY="off" go build -json hello.go
{"ImportPath":"golang.org/x/crypto/acme/autocert","Action":"build-output","Output":"hello.go:6:2: golang.org/x/crypto@v0.36.0: module lookup disabled by GOPROXY=off\n"}
{"ImportPath":"golang.org/x/crypto/acme/autocert","Action":"build-fail"}
{"ImportPath":"golang.org/x/net/html/charset","Action":"build-output","Output":"hello.go:7:2: golang.org/x/crypto@v0.36.0: module lookup disabled by GOPROXY=off\n"}
{"ImportPath":"golang.org/x/net/html/charset","Action":"build-fail"}

Finally, if I disable "workspace mode" by renaming the go.work file I get error messages that don't say explicitly which import failed, but at least don't give the wrong path:

$ mv ../go.work ../go.work.bak
$ GOPROXY="off" go build hello.go
go: downloading golang.org/x/net v0.21.0
go: downloading golang.org/x/crypto v0.36.0
hello.go:6:2: module lookup disabled by GOPROXY=off
hello.go:7:2: module lookup disabled by GOPROXY=off

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReportIssues describing a possible bug in the Go implementation.GoCommandcmd/goNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    Status
    Todo

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions