Go-tools: Checking specific package causes staticcheck to drop all output

Created on 13 Aug 2019  路  3Comments  路  Source: dominikh/go-tools

For some reason, including this directory in a staticcheck call causes it to drop all output: https://github.com/kubernetes/kubernetes/tree/master/staging/src/k8s.io/kubectl/pkg/cmd/edit/testdata

Steps to reproduce:

  1. Check out k8s.io/kubernetes from github.com/kubernetes/kubernetes@31bade3822cfdb919a388003d953d4141edb28e9
  2. On directories:

    1. Run staticcheck -checks "all" ./vendor/k8s.io/kubectl/pkg/cmd/edit/testdata ./pkg/kubelet. Note the lack of output, and how quickly the program terminates.

    2. Now run staticcheck -checks "all" ./pkg/kubelet, and observe the output issues.

  3. On files:

    1. Run staticcheck -checks "all" ./vendor/k8s.io/kubectl/pkg/cmd/edit/testdata/record.go ./pkg/kubelet/kubelet.go. Note the lack of output, and how quickly the program terminates.

    2. Now run staticcheck -checks "all" ./pkg/kubelet/kubelet.go, and observe the output issues.

  4. It does _not_ reproduce on packages:

    1. Run staticcheck -checks "all" k8s.io/kubernetes/vendor/k8s.io/kubectl/pkg/cmd/edit/testdata k8s.io/kubernetes/pkg/kubelet, and observe the output issues

    2. Now run staticcheck -checks "all" k8s.io/kubernetes/pkg/kubelet, outputs the same issues

Including other packages in Kubernetes does not trigger this problem.

$ staticcheck -debug.version:
staticcheck (no version)

Compiled with Go version: go1.12.5
Built without Go modules
$ go version
go version go1.12.5 linux/amd64
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/usr/local/google/home/stclair/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/usr/local/google/home/stclair/go/k8s3"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/google/home/stclair/.gvm/gos/go1.12.5"
GOTMPDIR=""
GOTOOLDIR="/usr/local/google/home/stclair/.gvm/gos/go1.12.5/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build083108145=/tmp/go-build -gno-record-gcc-switches"

Version is built from honnef.co/go/tools => honnef.co/go/tools v0.0.1-2019.2.2

bug upstream

Most helpful comment

These are indeed all upstream issues. go/packages is not correctly reporting some of the errors that go list -e is (incorrectly) printing.

I'll leave this issue open until the issues have been addressed upstream.

All 3 comments

A quick first triage shows a combination of bugs in staticcheck (or possibly go/packages), possibly in Go, and user error.

The issue in staticcheck is that it seemingly terminates successfully upon receiving arguments that are invalid. That I will have to diagnose in depth.

As for invalid arguments, I observe the following:

  1. go list ./vendor/k8s.io/kubectl/pkg/cmd/edit/testdata reports the following:
unexpected directory layout:
    import path: gopkg.in/yaml.v2
    root: /home/dominikh/prj/src
    dir: /home/dominikh/prj/src/k8s.io/kubernetes/vendor/gopkg.in/yaml.v2
    expand root: /home/dominikh/prj/src
    expand dir: /home/dominikh/prj/src/k8s.io/kubernetes/vendor/gopkg.in/yaml.v2
    separator: /

This looks related to https://github.com/golang/go/issues/24854

Furthermore, go list k8s.io/kubernetes/vendor/k8s.io/kubectl/pkg/cmd/edit/testdata succeeds, which explains why that invocation of staticcheck works correctly, too.

  1. Running staticcheck on files from different directories is not valid, in the same way that go build forbids it:
go build /tmp/foo.go /tmp/bar/foo.go 
named files must all be in one directory; have /tmp/ and /tmp/bar/

Staticcheck, again, drops this error on the floor for some reason.

These are indeed all upstream issues. go/packages is not correctly reporting some of the errors that go list -e is (incorrectly) printing.

I'll leave this issue open until the issues have been addressed upstream.

golang/tools@597f57769402f90a9c238d64701717ff5fe472d6 should fix this issue. Note that I haven't yet updated the go.mod in this repository, though. I'll do that soon.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jadekler picture jadekler  路  3Comments

dominikh picture dominikh  路  3Comments

dominikh picture dominikh  路  4Comments

dominikh picture dominikh  路  3Comments

jtreleaven picture jtreleaven  路  3Comments