From cb0b3361806ffaceeb9b0c4893144fad72d0d10b Mon Sep 17 00:00:00 2001 From: Michael Matloob Date: Wed, 3 Oct 2018 10:48:25 -0400 Subject: [PATCH] go/packages: pass through packages with error in the fallback This applies a part of golang.org/cl/137075 to the fallback. If go list doesn't find a package, it returns an almost empty package structure with an error set on it. That change passed through those packages from the 1.11+ go list, so users could determine there wasn't a match. This change does the same from the go 1.10 fallback go list code. Change-Id: I98acc186c0a9eeef0416e9fec0e1fe0e29ddc51c Reviewed-on: https://go-review.googlesource.com/c/139158 Reviewed-by: Alan Donovan --- go/packages/golist_fallback.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/go/packages/golist_fallback.go b/go/packages/golist_fallback.go index 02816342..21cffac7 100644 --- a/go/packages/golist_fallback.go +++ b/go/packages/golist_fallback.go @@ -49,7 +49,7 @@ func golistDriverFallback(cfg *Config, words ...string) (*driverResponse, error) addPackage := func(p *jsonPackage) { id := p.ImportPath - if p.Name == "" || allPkgs[id] { + if allPkgs[id] { return } allPkgs[id] = true @@ -133,6 +133,12 @@ func golistDriverFallback(cfg *Config, words ...string) (*driverResponse, error) Imports: importMap(p.Imports), // TODO(matloob): set errors on the Package to cgoErrors } + if p.Error != nil { + pkg.Errors = append(pkg.Errors, Error{ + Pos: p.Error.Pos, + Msg: p.Error.Err, + }) + } response.Packages = append(response.Packages, pkg) if cfg.Tests && isRoot { testID := fmt.Sprintf("%s [%s.test]", id, id)