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

x/tools/go/packages: "internal error: nil Pkg importing" #33554

Closed
jayconrod opened this issue Aug 8, 2019 · 3 comments
Closed

x/tools/go/packages: "internal error: nil Pkg importing" #33554

jayconrod opened this issue Aug 8, 2019 · 3 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@jayconrod
Copy link
Contributor

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

$ go version
go version devel +0ca4f6be35 Wed Aug 7 14:40:17 2019 +0000 darwin/amd64

Does this issue reproduce with the latest release?

n/a

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/jayconrod/Library/Caches/go-build"
GOENV="/Users/jayconrod/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/jayconrod/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/jayconrod/Code/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/jayconrod/Code/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/jayconrod/Code/test/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/rq/x0692kqj6ml8cvrhcqh5bswc008xj1/T/go-build252241896=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

go run load.go

in the workspace described by:

-- a/a.go --
package a

import _ "m/b"
-- b/b.go --
package b
-- go.mod --
module m

go 1.13

require golang.org/x/tools v0.0.0-20190808195139-e713427fea3f // indirect
-- load.go --
// +build ignore

package main

import (
	"fmt"
	"log"

	"golang.org/x/tools/go/packages"
)

func main() {
	cfg := &packages.Config{
		Mode: packages.NeedName | packages.NeedTypes | packages.NeedImports,
	}
	pkgs, err := packages.Load(cfg, "m/a", "m/b")
	if err != nil {
		log.Fatal(err)
	}
	for _, pkg := range pkgs {
		fmt.Println(pkg.PkgPath)
	}
}

What did you expect to see?

Test program should print:

m/a
m/b

What did you see instead?

2019/08/08 17:14:09 internal error: nil Pkg importing "m/b" from "m/a"
exit status 1

The error message is coming from golang.org/x/tools/go/packages.loader.loadPackage. I think the problem is that I asked for NeedTypes and NeedImports but not NeedDeps, which may or may not make sense. We shouldn't be exiting with an internal error in any case though.

cc @matloob

@jayconrod jayconrod added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Aug 8, 2019
@jayconrod jayconrod added this to the Unreleased milestone Aug 8, 2019
@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Sep 12, 2019
@mewmew
Copy link
Contributor

mewmew commented Nov 1, 2019

I also ran into this issue today. However, adding NeedDeps did not resolve it. Any other ideas on what the cause may be @jayconrod and @matloob?

Edit: I can confirm that this issue was present in an older x/tools, but no longer present in a more recent rev of x/tools.

issue present: golang.org/x/tools v0.0.0-20190325223049-1d95b17f1b04 // indirect
issue absent:  golang.org/x/tools v0.0.0-20191031220737-6d8f1af9ccc0 // indirect

@matloob
Copy link
Contributor

matloob commented Nov 1, 2019

This seems to be fixed at head (and was able to confirm the fix locally), so I'll close the issue. Let me know if it pops up again.

@matloob matloob closed this as completed Nov 1, 2019
ksoichiro added a commit to ksoichiro/go-consistent that referenced this issue Mar 29, 2020
From go 1.14, an error occurs:
internal error: nil Pkg importing "go/ast" from "github.com/quasilyte/go-consistent [github.com/quasilyte/go-consistent.test]"

To fix this, update x/tools:
go get golang.org/x/tools && go mod tidy

Related:
golang/go#33554
ksoichiro added a commit to ksoichiro/go-mnd that referenced this issue Mar 29, 2020
From go 1.14, an error occurs:
internal error: nil Pkg importing "go/ast" from "github.com/quasilyte/go-consistent [github.com/quasilyte/go-consistent.test]"

To fix this, update x/tools:
go get golang.org/x/tools && go mod tidy

Related:
golang/go#33554
quasilyte pushed a commit to quasilyte/go-consistent that referenced this issue Apr 4, 2020
From go 1.14, an error occurs:
internal error: nil Pkg importing "go/ast" from "github.com/quasilyte/go-consistent [github.com/quasilyte/go-consistent.test]"

To fix this, update x/tools:
go get golang.org/x/tools && go mod tidy

Related:
golang/go#33554
@thockin
Copy link

thockin commented Jun 17, 2020

I'm now getting this in this context:

pkgs, err := packages.Load(&packages.Config{Mode: packages.NeedName | packages.NeedFiles | packages.NeedTypes | packages.NeedDeps | packages.NeedImports}, c.dirs...)

results in internal error: nil Pkg importing "errors" from "plugin"

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. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

5 participants