From f98590f1bfc84d0afb884c0444d6ba8cef01fff8 Mon Sep 17 00:00:00 2001 From: Rebecca Stambler Date: Tue, 28 May 2019 16:32:04 -0400 Subject: [PATCH] go/packages: handle potential nil pointer error Change-Id: I2b889e1d5ec07d9271292c58b896f6c0c7155cf3 Reviewed-on: https://go-review.googlesource.com/c/tools/+/179220 Run-TryBot: Rebecca Stambler Run-TryBot: Michael Matloob Reviewed-by: Michael Matloob --- go/packages/golist.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/go/packages/golist.go b/go/packages/golist.go index 53898490366..72c0c5d632d 100644 --- a/go/packages/golist.go +++ b/go/packages/golist.go @@ -172,7 +172,19 @@ extractQueries: // Check candidate packages for containFiles. if len(containFiles) > 0 { for _, id := range containsCandidates { - pkg := response.seenPackages[id] + pkg, ok := response.seenPackages[id] + if !ok { + response.addPackage(&Package{ + ID: id, + Errors: []Error{ + { + Kind: ListError, + Msg: fmt.Sprintf("package %s expected but not seen", id), + }, + }, + }) + continue + } for _, f := range containFiles { for _, g := range pkg.GoFiles { if sameFile(f, g) {