Skip to content

Commit

Permalink
go/packages: handle variation an an error message
Browse files Browse the repository at this point in the history
go/packages has a special case for cmd/go errors that result from
errors running the 'pkg-config' tool. When modules are missing from
the module cache cmd/go can download modules, and log a message for
each downloaded module, so add a special case to the special case
to check for that message.

Also remove a usage of the x/xerrors package now that it's been folded
into the stdlib for a while.

Fixes golang/go#36770

Change-Id: If1cf8c5d83ac84a51b8bafc4930a0869674d216a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/261502
Trust: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
  • Loading branch information
matloob committed Nov 16, 2020
1 parent 6f6c72a commit 1d69943
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion go/packages/golist.go
Original file line number Diff line number Diff line change
Expand Up @@ -902,8 +902,13 @@ func (state *golistState) invokeGo(verb string, args ...string) (*bytes.Buffer,
return unicode.IsOneOf([]*unicode.RangeTable{unicode.L, unicode.M, unicode.N, unicode.P, unicode.S}, r) &&
!strings.ContainsRune("!\"#$%&'()*,:;<=>?[\\]^`{|}\uFFFD", r)
}
// golang/go#36770: Handle case where cmd/go prints module download messages before the error.
msg := stderr.String()
for strings.HasPrefix(msg, "go: downloading") {
msg = msg[strings.IndexRune(msg, '\n')+1:]
}
if len(stderr.String()) > 0 && strings.HasPrefix(stderr.String(), "# ") {
msg := stderr.String()[len("# "):]
msg := msg[len("# "):]
if strings.HasPrefix(strings.TrimLeftFunc(msg, isPkgPathRune), "\n") {
return stdout, nil
}
Expand Down

0 comments on commit 1d69943

Please sign in to comment.