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

cmd/go: go list -e should list a package containing an error if files named on the command line do not exist #29280

Open
mvdan opened this issue Dec 15, 2018 · 13 comments

Comments

@mvdan
Copy link
Member

commented Dec 15, 2018

$ 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

@mvdan mvdan added the NeedsFix label Dec 15, 2018

@gopherbot gopherbot added this to the Unreleased milestone Dec 15, 2018

@gopherbot

This comment has been minimized.

Copy link

commented Dec 17, 2018

Change https://golang.org/cl/154517 mentions this issue: go/packages: suppress go list errors when ad-hoc package doesn't exist

@matloob

This comment has been minimized.

Copy link
Contributor

commented Dec 17, 2018

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.

gopherbot pushed a commit to golang/tools that referenced this issue Dec 17, 2018

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/154517
Reviewed-by: Ian Cottrell <iancottrell@google.com>
@mvdan

This comment has been minimized.

Copy link
Member Author

commented Dec 18, 2018

Thanks for the quick reply. It sounds to me like most tools out there want to check for most or all errors, and the fact that Load returns an error seems to tell that it's enough to check that one. So it can be easy to forget to check each package's Errors field.

Perhaps this should be clearer in the docs, e.g. via an example that most static analysis tools should follow.

Edit: I just realised that the package example does include packages.PrintErrors(pkgs) - I had missed that.

@mvdan

This comment has been minimized.

Copy link
Member Author

commented Dec 18, 2018

Here's another bug - missing files in syntax mode produce no command-line-arguments package at all, which seems like a bug to me too:

$ gopackages -mode syntax empty.go
Go package "command-line-arguments":
        package
        has complete exported type info
        -:
empty.go:1:1: expected 'package', found 'EOF'
$ gopackages -mode syntax missing.go

This is on x/tools 13ba8ad772dfbf0f451b5dd0679e9c5605afc05d and go version devel +47fb1fbd55 Fri Dec 14 16:18:51 2018 +0000 linux/amd64.

mvdan added a commit to mvdan/gogrep that referenced this issue Dec 18, 2018

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
another bug in go/packages. See golang/go#29280.
@dominikh

This comment has been minimized.

Copy link
Member

commented Jan 4, 2019

It should be noted that this issue is (no longer?) limited to LoadSyntax. It occurs in all modes.

desktop ~ $ for mode in files imports types syntax allsyntax; do gopackages -mode $mode /does/definitely/not/exist.go; echo $?; done
0
0
0
0
0
@matloob

This comment has been minimized.

Copy link
Contributor

commented Jan 8, 2019

@dominikh I think the 0 exit status is working as intended. In these cases, go/packages should return a package with a non-empty Errors field. Is it not doing that?

@dominikh

This comment has been minimized.

Copy link
Member

commented Jan 8, 2019

@matloob for me, it returns zero packages and no error.

@mvdan

This comment has been minimized.

Copy link
Member Author

commented Apr 5, 2019

@matloob I think you forgot to repurpose this issue?

@matloob matloob changed the title x/tools/go/packages: LoadSyntax doesn't error with missing files cmd/go: go list -e should exit 0 with a package containing an error when ad-hoc package doesn't exist Apr 5, 2019

@matloob

This comment has been minimized.

Copy link
Contributor

commented Apr 5, 2019

@mvdan I retitled the issue, sorry about that!
@dominikh Hmm... let me look into that...

@gopherbot

This comment has been minimized.

Copy link

commented Apr 5, 2019

Change https://golang.org/cl/171018 mentions this issue: go/packages: add a work around for go list behavior for missing ad-hoc package

gopherbot pushed a commit to golang/tools that referenced this issue Apr 8, 2019

go/packages: add a work around for go list behavior for missing ad-ho…
…c 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. Since it doesn't do that
yet, add a work-around.

Updates golang/go#29280

Change-Id: I6019f28ce4770582f274919d1aa35d85a634687e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/171018
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
@bcmills

This comment has been minimized.

Copy link
Member

commented Apr 19, 2019

@matloob, could you clarify the issue with cmd/go? I don't know what an “ad-hoc” package is or what it means for such a thing not to exist.

@ianthehat

This comment has been minimized.

Copy link

commented Apr 19, 2019

An ad-hoc package is the term used throughout the tools for one formed when you pass the go command a list of files.
@matloob means that one or more of the files did not exist, which should result in an error on the package in the output, not go list failing.

@bcmills bcmills changed the title cmd/go: go list -e should exit 0 with a package containing an error when ad-hoc package doesn't exist cmd/go: go list -e should list a package containing an error if files named on the command line do not exist Apr 19, 2019

@bcmills bcmills removed the WaitingForInfo label Apr 19, 2019

@bcmills bcmills modified the milestones: Unreleased, Go1.13 Apr 19, 2019

@andybons andybons modified the milestones: Go1.13, Go1.14 Jul 8, 2019

@gopherbot

This comment has been minimized.

Copy link

commented Jul 9, 2019

Change https://golang.org/cl/185345 mentions this issue: cmd/go: rationalize errors in internal/load and internal/modload

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants
You can’t perform that action at this time.