go: cmd/go: go list -e should list a package containing an error if files named on the command line do not exist
$ go version
go version devel +47fb1fbd55 Fri Dec 14 16:18:51 2018 +0000 linux/amd64
$ cd go/src/golang.org/x/tools
$ git show HEAD --no-patch
commit 3c39ce7b61056afe4473b651789da5f89d4aeb20 (HEAD -> master, origin/master, origin/HEAD)
Author: Brad Fitzpatrick <bradfitz@golang.org>
Date: Fri Dec 14 14:45:46 2018 +0000
tip: fix, update tip.golang.org
[...]
$ go install ./go/packages/gopackages
$ gopackages missing.go; echo $?
gopackages: go [list -e -json -compiled -test=false -export=false -deps=true -- missing.go]: exit status 1: stat missing.go: no such file or directory
1
$ gopackages -mode syntax missing.go; echo $?
0
Seems to me like the LoadSyntax
mode should error too. Found while porting https://github.com/mvdan/gogrep from go/loader
to go/packages
, since some error test cases stopped erroring as expected.
/cc @ianthehat @matloob
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 15 (11 by maintainers)
Commits related to this issue
- go/packages: suppress go list errors when ad-hoc package doesn't exist Updates golang/go#29280 Change-Id: Ie5a5dc1fef8f3d989b3a5fffb6c2ca66e97c143a Reviewed-on: https://go-review.googlesource.com/c/... — committed to golang/tools by matloob 6 years ago
- stop on package load errors too I had forgotten to check those. Otherwise, we might be ignoring parse or typecheck errors. We can't fix the TODO in load_test.go yet, because it looks like there's an... — committed to mvdan/gogrep by mvdan 6 years ago
- go/packages: add a work around for go list behavior for missing ad-hoc package If a file in an ad-hoc package doesn't exist, go list should exit 0 and return an dummy package with an error set on it.... — committed to golang/tools by matloob 5 years ago
- cmd/go: rationalize errors in internal/load and internal/modload This change is a non-minimal fix for #32917, but incidentally fixes several other bugs and makes the error messages much more ergonomi... — committed to golang/go by bcmills 5 years ago
@mvdan I retitled the issue, sorry about that! @dominikh Hmm… let me look into that…
The underlying problem is that go list -e doesn’t exit 0 (as it should) when an ad-hoc package doesn’t exist. I’ve sent a cl to suppress the error in go packages, and then I’ll re-purpose this bug to target that issue.