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, x/tools/go/packages: confusing go list repeated package with different values error #30519

Open
nhooyr opened this issue Mar 1, 2019 · 6 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@nhooyr
Copy link
Contributor

nhooyr commented Mar 1, 2019

On go 1.12

Reproducible repo at https://github.com/nhooyr/gomod

I'm importing a main package as a side effect import which is an error. I'm aware this is wrong, but the error message should be clearer. If you try and load the mod with x/tools/go/packages, it will fail with

go list repeated package golang.org/x/tools/cmd/goimports with different values

Which is a very confusing error.

I debugged this a bit and it looks like go list is returning two different entries for goimports

If you run

$ go list -deps=true all | grep goimports

You'll see

$ go list -deps=true all | grep goimports
golang.org/x/tools/cmd/goimports
golang.org/x/tools/cmd/goimports

Thing is, these two listing are actually different. If you run with the json option.

{
	"Dir": "/Users/nhooyr/Programming/gopath/pkg/mod/golang.org/x/tools@v0.0.0-20190228203856-589c23e65e65/cmd/goimports",
	"ImportPath": "golang.org/x/tools/cmd/goimports",
	"Name": "main",
	"Doc": "Command goimports updates your Go import lines, adding missing ones and removing unreferenced ones.",
	"Target": "/Users/nhooyr/Programming/gopath/bin/goimports",
	"Module": {
		"Path": "golang.org/x/tools",
		"Version": "v0.0.0-20190228203856-589c23e65e65",
		"Time": "2019-02-28T20:38:56Z",
		"Dir": "/Users/nhooyr/Programming/gopath/pkg/mod/golang.org/x/tools@v0.0.0-20190228203856-589c23e65e65",
		"GoMod": "/Users/nhooyr/Programming/gopath/pkg/mod/cache/download/golang.org/x/tools/@v/v0.0.0-20190228203856-589c23e65e65.mod"
	},
	"DepOnly": true,
	"Stale": true,
	"StaleReason": "stale dependency: golang.org/x/tools/internal/semver",
	"GoFiles": [
		"doc.go",
		"goimports.go",
		"goimports_gc.go"
	],
	"IgnoredGoFiles": [
		"goimports_not_gc.go"
	],
	"Imports": [
		"bufio",
		"bytes",
		"errors",
		"flag",
		"fmt",
		"go/scanner",
		"golang.org/x/tools/imports",
		"io",
		"io/ioutil",
		"log",
		"os",
		"os/exec",
		"path/filepath",
		"runtime",
		"runtime/pprof",
		"runtime/trace",
		"strings"
	],
	"Deps": [
		"bufio",
		"bytes",
		"compress/flate",
		"compress/gzip",
		"container/heap",
		"context",
		"encoding",
		"encoding/base64",
		"encoding/binary",
		"encoding/json",
		"errors",
		"flag",
		"fmt",
		"go/ast",
		"go/build",
		"go/constant",
		"go/doc",
		"go/format",
		"go/parser",
		"go/printer",
		"go/scanner",
		"go/token",
		"go/types",
		"golang.org/x/tools/go/ast/astutil",
		"golang.org/x/tools/go/gcexportdata",
		"golang.org/x/tools/go/internal/cgo",
		"golang.org/x/tools/go/internal/gcimporter",
		"golang.org/x/tools/go/internal/packagesdriver",
		"golang.org/x/tools/go/packages",
		"golang.org/x/tools/imports",
		"golang.org/x/tools/internal/fastwalk",
		"golang.org/x/tools/internal/gopathwalk",
		"golang.org/x/tools/internal/module",
		"golang.org/x/tools/internal/semver",
		"hash",
		"hash/crc32",
		"internal/bytealg",
		"internal/cpu",
		"internal/fmtsort",
		"internal/goroot",
		"internal/poll",
		"internal/race",
		"internal/syscall/unix",
		"internal/testlog",
		"io",
		"io/ioutil",
		"log",
		"math",
		"math/big",
		"math/bits",
		"math/rand",
		"net/url",
		"os",
		"os/exec",
		"path",
		"path/filepath",
		"reflect",
		"regexp",
		"regexp/syntax",
		"runtime",
		"runtime/internal/atomic",
		"runtime/internal/math",
		"runtime/internal/sys",
		"runtime/pprof",
		"runtime/trace",
		"sort",
		"strconv",
		"strings",
		"sync",
		"sync/atomic",
		"syscall",
		"text/scanner",
		"text/tabwriter",
		"text/template",
		"text/template/parse",
		"time",
		"unicode",
		"unicode/utf16",
		"unicode/utf8",
		"unsafe"
	],
	"Error": {
		"ImportStack": [
			"example.com/mymod",
			"golang.org/x/tools/cmd/goimports"
		],
		"Pos": "doc.go:4:5",
		"Err": "import \"golang.org/x/tools/cmd/goimports\" is a program, not an importable package"
	}
}
{
	"Dir": "/Users/nhooyr/Programming/gopath/pkg/mod/golang.org/x/tools@v0.0.0-20190228203856-589c23e65e65/cmd/goimports",
	"ImportPath": "golang.org/x/tools/cmd/goimports",
	"Name": "main",
	"Doc": "Command goimports updates your Go import lines, adding missing ones and removing unreferenced ones.",
	"Target": "/Users/nhooyr/Programming/gopath/bin/goimports",
	"Module": {
		"Path": "golang.org/x/tools",
		"Version": "v0.0.0-20190228203856-589c23e65e65",
		"Time": "2019-02-28T20:38:56Z",
		"Dir": "/Users/nhooyr/Programming/gopath/pkg/mod/golang.org/x/tools@v0.0.0-20190228203856-589c23e65e65",
		"GoMod": "/Users/nhooyr/Programming/gopath/pkg/mod/cache/download/golang.org/x/tools/@v/v0.0.0-20190228203856-589c23e65e65.mod"
	},
	"Match": [
		"all"
	],
	"Stale": true,
	"StaleReason": "stale dependency: golang.org/x/tools/internal/semver",
	"GoFiles": [
		"doc.go",
		"goimports.go",
		"goimports_gc.go"
	],
	"IgnoredGoFiles": [
		"goimports_not_gc.go"
	],
	"Imports": [
		"bufio",
		"bytes",
		"errors",
		"flag",
		"fmt",
		"go/scanner",
		"golang.org/x/tools/imports",
		"io",
		"io/ioutil",
		"log",
		"os",
		"os/exec",
		"path/filepath",
		"runtime",
		"runtime/pprof",
		"runtime/trace",
		"strings"
	],
	"Deps": [
		"bufio",
		"bytes",
		"compress/flate",
		"compress/gzip",
		"container/heap",
		"context",
		"encoding",
		"encoding/base64",
		"encoding/binary",
		"encoding/json",
		"errors",
		"flag",
		"fmt",
		"go/ast",
		"go/build",
		"go/constant",
		"go/doc",
		"go/format",
		"go/parser",
		"go/printer",
		"go/scanner",
		"go/token",
		"go/types",
		"golang.org/x/tools/go/ast/astutil",
		"golang.org/x/tools/go/gcexportdata",
		"golang.org/x/tools/go/internal/cgo",
		"golang.org/x/tools/go/internal/gcimporter",
		"golang.org/x/tools/go/internal/packagesdriver",
		"golang.org/x/tools/go/packages",
		"golang.org/x/tools/imports",
		"golang.org/x/tools/internal/fastwalk",
		"golang.org/x/tools/internal/gopathwalk",
		"golang.org/x/tools/internal/module",
		"golang.org/x/tools/internal/semver",
		"hash",
		"hash/crc32",
		"internal/bytealg",
		"internal/cpu",
		"internal/fmtsort",
		"internal/goroot",
		"internal/poll",
		"internal/race",
		"internal/syscall/unix",
		"internal/testlog",
		"io",
		"io/ioutil",
		"log",
		"math",
		"math/big",
		"math/bits",
		"math/rand",
		"net/url",
		"os",
		"os/exec",
		"path",
		"path/filepath",
		"reflect",
		"regexp",
		"regexp/syntax",
		"runtime",
		"runtime/internal/atomic",
		"runtime/internal/math",
		"runtime/internal/sys",
		"runtime/pprof",
		"runtime/trace",
		"sort",
		"strconv",
		"strings",
		"sync",
		"sync/atomic",
		"syscall",
		"text/scanner",
		"text/tabwriter",
		"text/template",
		"text/template/parse",
		"time",
		"unicode",
		"unicode/utf16",
		"unicode/utf8",
		"unsafe"
	]
}

Not sure what's causing this difference between the two listings.

Diff

14c14,16
< 	"DepOnly": true,
---
> 	"Match": [
> 		"all"
> 	],
125,133c127
< 	],
< 	"Error": {
< 		"ImportStack": [
< 			"example.com/mymod",
< 			"golang.org/x/tools/cmd/goimports"
< 		],
< 		"Pos": "doc.go:4:5",
< 		"Err": "import \"golang.org/x/tools/cmd/goimports\" is a program, not an importable package"
< 	}
---
> 	]

Furthermore, this goes away if you use ./....

$ go list -deps=true ./... | grep goimports
golang.org/x/tools/cmd/goimports

I can reproduce this in other cases as well e.g. when using an internal package where it isn't accessible (in this case both all and ./... produce the same output).

To summarize, the x/tools/go/packages error should be clearer, go list should not produce different listings of the same package and ./... and all should produce the same output.

@nhooyr nhooyr changed the title cmd/go, x/tools/go/packages: confusing go list repeated package with different values cmd/go, x/tools/go/packages: confusing go list repeated package with different values error Mar 1, 2019
@bcmills
Copy link
Contributor

bcmills commented Mar 1, 2019

CC @matloob @ianthehat @jayconrod

@bcmills bcmills added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Mar 1, 2019
@bcmills
Copy link
Contributor

bcmills commented Mar 1, 2019

Please include the output of go env.

@bcmills bcmills added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Mar 1, 2019
@bcmills bcmills added this to the Go1.13 milestone Mar 1, 2019
@nhooyr
Copy link
Contributor Author

nhooyr commented Mar 1, 2019

GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/nhooyr/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/nhooyr/Programming/gopath"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.12/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.12/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/tmp/gomod/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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/7b/218sfv615xxf_w9ttnpjt0_r0000gn/T/go-build183618286=/tmp/go-build -gno-record-gcc-switches -fno-common"

@bcmills bcmills removed the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Mar 1, 2019
@matloob matloob self-assigned this Mar 4, 2019
@gopherbot
Copy link

Change https://golang.org/cl/168657 mentions this issue: go/packages: make error message for conflicting packages more clear

@matloob
Copy link
Contributor

matloob commented Mar 21, 2019

Hi, I've sent change https://golang.org/cl/168657 to make the error more clear on the go/packages side. Please comment if you have ideas to make it more clear

gopherbot pushed a commit to golang/tools that referenced this issue Mar 21, 2019
Make it slightly more clear that this is not a user error, but an
internal error.

Updates golang/go#30519

Change-Id: I7adb3b5bb1548eab8e46db48946d55f9d59a4311
Reviewed-on: https://go-review.googlesource.com/c/tools/+/168657
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
@matloob
Copy link
Contributor

matloob commented Mar 21, 2019

I've submitted my change.

@matloob matloob removed their assignment Mar 21, 2019
@andybons andybons modified the milestones: Go1.13, Go1.14 Jul 8, 2019
@rsc rsc modified the milestones: Go1.14, Backlog Oct 9, 2019
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

6 participants