Skip to content
This repository has been archived by the owner on Apr 10, 2019. It is now read-only.

Files in /usr/local/go are processed #149

Closed
Dynom opened this issue Jul 18, 2016 · 23 comments
Closed

Files in /usr/local/go are processed #149

Dynom opened this issue Jul 18, 2016 · 23 comments

Comments

@Dynom
Copy link

Dynom commented Jul 18, 2016

I'm not (yet) sure why, but some linters generate a report from /usr/local/go.

mark@Dymek:$ gometalinter -j4 --vendor --deadline=30s -t . | grep '^/'
/usr/local/go/src/os/user/lookup.go:9:9:warning: undeclared name: current (unconvert)
/usr/local/go/src/os/user/lookup.go:15:9:warning: undeclared name: lookup (unconvert)
/usr/local/go/src/os/user/lookup.go:21:9:warning: undeclared name: lookupId (unconvert)
/usr/local/go/src/net/lookup_unix.go:55:24:warning: undeclared name: cgoLookupHost (unconvert)
/usr/local/go/src/net/lookup_unix.go:67:24:warning: undeclared name: cgoLookupIP (unconvert)
/usr/local/go/src/net/lookup_unix.go:78:23:warning: undeclared name: cgoLookupPort (unconvert)
/usr/local/go/src/net/lookup_unix.go:87:24:warning: undeclared name: cgoLookupCNAME (unconvert)
/usr/local/go/src/net/lookup_unix.go:154:23:warning: undeclared name: cgoLookupPTR (unconvert)
/usr/local/go/src/crypto/x509/root.go:15:10:warning: undeclared name: initSystemRoots (unconvert)
/usr/local/go/src/os/user/lookup.go:9:9:warning: unused global variable undeclared name: current (varcheck)
/usr/local/go/src/os/user/lookup.go:15:9:warning: unused global variable undeclared name: lookup (varcheck)
/usr/local/go/src/os/user/lookup.go:21:9:warning: unused global variable undeclared name: lookupId (varcheck)
/usr/local/go/src/net/lookup_unix.go:55:24:warning: unused global variable undeclared name: cgoLookupHost (varcheck)
/usr/local/go/src/net/lookup_unix.go:67:24:warning: unused global variable undeclared name: cgoLookupIP (varcheck)
/usr/local/go/src/net/lookup_unix.go:78:23:warning: unused global variable undeclared name: cgoLookupPort (varcheck)
/usr/local/go/src/net/lookup_unix.go:87:24:warning: unused global variable undeclared name: cgoLookupCNAME (varcheck)
/usr/local/go/src/net/lookup_unix.go:154:23:warning: unused global variable undeclared name: cgoLookupPTR (varcheck)
/usr/local/go/src/crypto/x509/root.go:15:10:warning: unused global variable undeclared name: initSystemRoots (varcheck)
/usr/local/go/src/os/user/lookup.go:9:9:warning: unused struct field undeclared name: current (structcheck)
/usr/local/go/src/os/user/lookup.go:15:9:warning: unused struct field undeclared name: lookup (structcheck)
/usr/local/go/src/os/user/lookup.go:21:9:warning: unused struct field undeclared name: lookupId (structcheck)
/usr/local/go/src/net/lookup_unix.go:55:24:warning: unused struct field undeclared name: cgoLookupHost (structcheck)
/usr/local/go/src/net/lookup_unix.go:67:24:warning: unused struct field undeclared name: cgoLookupIP (structcheck)
/usr/local/go/src/net/lookup_unix.go:78:23:warning: unused struct field undeclared name: cgoLookupPort (structcheck)
/usr/local/go/src/net/lookup_unix.go:87:24:warning: unused struct field undeclared name: cgoLookupCNAME (structcheck)
/usr/local/go/src/net/lookup_unix.go:154:23:warning: unused struct field undeclared name: cgoLookupPTR (structcheck)
/usr/local/go/src/crypto/x509/root.go:15:10:warning: unused struct field undeclared name: initSystemRoots (structcheck)
/usr/local/go/src/os/user/lookup.go:9:9:warning: undeclared name: current (aligncheck)
/usr/local/go/src/os/user/lookup.go:15:9:warning: undeclared name: lookup (aligncheck)
/usr/local/go/src/os/user/lookup.go:21:9:warning: undeclared name: lookupId (aligncheck)
/usr/local/go/src/net/lookup_unix.go:55:24:warning: undeclared name: cgoLookupHost (aligncheck)
/usr/local/go/src/net/lookup_unix.go:67:24:warning: undeclared name: cgoLookupIP (aligncheck)
/usr/local/go/src/net/lookup_unix.go:78:23:warning: undeclared name: cgoLookupPort (aligncheck)
/usr/local/go/src/net/lookup_unix.go:87:24:warning: undeclared name: cgoLookupCNAME (aligncheck)
/usr/local/go/src/net/lookup_unix.go:154:23:warning: undeclared name: cgoLookupPTR (aligncheck)
/usr/local/go/src/crypto/x509/root.go:15:10:warning: undeclared name: initSystemRoots (aligncheck)

I'm on go version go1.6.2 darwin/amd64

mark@Dymek:$ set | grep ^GO
GOBIN=/Users/mark/Development/GO/bin
GOPATH=/Users/mark/Development/GO
GOROOT=/usr/local/go

/usr/local/go is a symlink, not sure if that's significant.

I've just ran gometalinter -fui with the assumption that all linters are up-to-date.

@alecthomas
Copy link
Owner

Can you walk through the steps in the contributing file? If it's a problem with a linter you should report it to that linter.

@Dynom
Copy link
Author

Dynom commented Jul 18, 2016

Hi,

I did but I kinda figured that if 4 linters produced the same behaviour that it wasn't related to those linters specifically. I also checked the two repositories and noone else filed a related bug, which struck me as weird. I can't be the only one with this problem...

But based on your reply I'm guessing I was wrong in that assumption!

@Dynom Dynom changed the title Files in /usr/local/go is processed Files in /usr/local/go are processed Jul 18, 2016
@Dynom Dynom closed this as completed Jul 18, 2016
@bkleef
Copy link

bkleef commented Nov 29, 2016

@Dynom did you ever found out what the real cause was (except Xcode)?

@Dynom
Copy link
Author

Dynom commented Nov 29, 2016

No I haven't found the root cause @bkleef. If you have the same issues and updating cgo/clang doesn't solve it than good luck!

@bkleef
Copy link

bkleef commented Nov 30, 2016

@Dynom I fixed it by moving /usr/local/go/bin/go to /usr/local/bin/go by ln -s /usr/local/go/bin/go /usr/local/bin/go and updated PATH from /go/bin:/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin to /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin.

@rayzyar
Copy link

rayzyar commented Jan 18, 2017

I encounter the same problem, and tried the solutions suggested above, but it did not work.
I have to rely on the exclude option, --exclude=/go/src/ should suppress the error

@cep21
Copy link

cep21 commented Mar 10, 2017

I occasionally see the same issue. Using exclude as well. Not sure how to reproduce.

@fho
Copy link
Contributor

fho commented May 4, 2017

I had the same issue.
The root of the problem was for me:

 # unparam ./...
exec: "gcc": executable file not found in $PATH
cgo failed: [go tool cgo -objdir /tmp/net_C645733397 -- -I /tmp/net_C645733397 cgo_linux.go cgo_resnew.go cgo_socknew.go cgo_unix.go]: exit status
1
exec: "gcc": executable file not found in $PATH
cgo failed: [go tool cgo -objdir /tmp/os_user_C355885168 -- -I /tmp/os_user_C355885168 getgrouplist_unix.go listgroups_unix.go lookup_unix.go]: exi
t status 1
/usr/local/go/src/os/user/lookup.go:38:9: undeclared name: listGroups
/usr/local/go/src/os/user/lookup.go:9:9: undeclared name: current
/usr/local/go/src/os/user/lookup.go:15:9: undeclared name: lookupUser
/usr/local/go/src/os/user/lookup.go:21:9: undeclared name: lookupUserId
/usr/local/go/src/os/user/lookup.go:27:9: undeclared name: lookupGroup
/usr/local/go/src/os/user/lookup.go:33:9: undeclared name: lookupGroupId
/usr/local/go/src/net/lookup_unix.go:54:24: undeclared name: cgoLookupHost
/usr/local/go/src/net/lookup_unix.go:69:24: undeclared name: cgoLookupIP
/usr/local/go/src/net/lookup_unix.go:81:23: undeclared name: cgoLookupPort
/usr/local/go/src/net/lookup_unix.go:97:24: undeclared name: cgoLookupCNAME
/usr/local/go/src/net/lookup_unix.go:164:23: undeclared name: cgoLookupPTR
couldn't load packages due to errors: net, os/user

The solution was to install gcc and a C std library (libc-dev)

@bkleef
Copy link

bkleef commented Jun 27, 2017

@rayzyar if you use the exclude option it still checks the files but ignores the output. So it takes more time than required which is far from perfect.

@bkleef
Copy link

bkleef commented Jun 27, 2017

This only occurs on Alpine based official Golang Docker images (golang:alpine) and not on (golang:latest) which is Debian based.

Reproduce by:

go get -u github.com/alecthomas/gometalinter
go gometalinter --install --debug
gometalinter --vendored-linters --vendor --disable-all -E vetshadow -E varcheck -E errcheck -E dupl -E ineffassign -E unconvert -E gosimple -E staticcheck -E gofmt -E unused --deadline=300s ./...

@dnephin
Copy link
Collaborator

dnephin commented Jun 27, 2017

As already mentioned one fix is to install gcc and the stdlib (should be musl-dev on alpine).

Another option is to set CGO_ENABLED=0

@aaronlehmann
Copy link

I suspect there is a race condition involved. I see this output sporadically. Without knowing the inner workings, perhaps the linting sometimes starts before the C compiler finishes. Or there might be problems with gometalinter running multiple linters concurrently, and having more than one of them try to invoke the compiler.

Another possibility could be the compiler failing somehow (perhaps running out of memory).

Will try the CGO_ENABLED=0 workaround.

@lkysow
Copy link

lkysow commented Dec 4, 2017

I've been getting this in circleci. It's intermittent and re-running usually fixes it so signs do point to a race condition. I've been using circleci/golang:1.8. Here's the errors from different failed builds.

gometalinter --disable gotype --disable gotypex --disable=gocyclo --disable golint --enable=megacheck --enable=unparam --linter='gas:gas -exclude=G104 -fmt=csv:^(?P<path>.*?\.go),(?P<line>\d+),(?P<message>[^,]+,[^,]+,[^,]+)' --deadline=300s --vendor -t --line-length=120 --skip server/static ./...
../../../../../usr/local/go/src/net/lookup_unix.go:54:24:warning: unused struct field undeclared name: cgoLookupHost (structcheck)
../../../../../usr/local/go/src/net/lookup_unix.go:69:24:warning: unused struct field undeclared name: cgoLookupIP (structcheck)
../../../../../usr/local/go/src/net/lookup_unix.go:81:23:warning: unused struct field undeclared name: cgoLookupPort (structcheck)
../../../../../usr/local/go/src/net/lookup_unix.go:97:24:warning: unused struct field undeclared name: cgoLookupCNAME (structcheck)
../../../../../usr/local/go/src/net/lookup_unix.go:164:23:warning: unused struct field undeclared name: cgoLookupPTR (structcheck)
gometalinter --disable gotype --disable gotypex --disable=gocyclo --disable golint --enable=megacheck --enable=unparam --deadline=300s --vendor -t --line-length=120 $(find . -type f -name '*.go' ! -path "./vendor/*" ! -path "./server/static/bindata_assetfs.go" ! -path "**/mocks/*" | xargs -I '{}' dirname '{}' | sort -u)
../../../../../usr/local/go/src/net/lookup_unix.go:54:24:warning: undeclared name: cgoLookupHost (interfacer)
../../../../../usr/local/go/src/net/lookup_unix.go:69:24:warning: undeclared name: cgoLookupIP (interfacer)
../../../../../usr/local/go/src/net/lookup_unix.go:81:23:warning: undeclared name: cgoLookupPort (interfacer)
../../../../../usr/local/go/src/net/lookup_unix.go:97:24:warning: undeclared name: cgoLookupCNAME (interfacer)
../../../../../usr/local/go/src/net/lookup_unix.go:164:23:warning: undeclared name: cgoLookupPTR (interfacer)

gometalinter --disable gotype --disable gotypex --disable=gocyclo --disable golint --enable=megacheck --enable=unparam --deadline=300s --vendor -t --line-length=120 $(find . -type f -name '*.go' ! -path "./vendor/*" ! -path "./server/static/bindata_assetfs.go" ! -path "**/mocks/*" | xargs -I '{}' dirname '{}' | sort -u)
../../../../../usr/local/go/src/mime/multipart/formdata.go:9:2:warning: could not import errors (readdirent: bad address) (maligned)
../../../../../usr/local/go/src/mime/multipart/writer.go:10:2:warning: could not import errors (readdirent: bad address) (maligned)
../../../../../usr/local/go/src/mime/multipart/formdata.go:61:17:warning: undeclared name: errors (maligned)
../../../../../usr/local/go/src/mime/multipart/writer.go:183:13:warning: undeclared name: errors (maligned)
../../../../../usr/local/go/src/mime/multipart/writer.go:47:10:warning: undeclared name: errors (maligned)
../../../../../usr/local/go/src/mime/multipart/writer.go:51:10:warning: undeclared name: errors (maligned)
../../../../../usr/local/go/src/mime/multipart/writer.go:61:10:warning: undeclared name: errors (maligned)

@dnephin
Copy link
Collaborator

dnephin commented Dec 4, 2017

Are you seeing this with v1 or master ?

@aaronlehmann
Copy link

I am seeing it with a build that was made from master. If I remember correctly, I had some performance problems with v1 that caused me to switch to master.

@lkysow
Copy link

lkysow commented Dec 4, 2017

I'm on master too

@vsayer
Copy link

vsayer commented Dec 5, 2017

Reproduced with go 1.9.2 and gometalinter 2.0.2, Used workaround of --exclude=/go/src/ which resolved it.

@atombender
Copy link

FWIW, I can reproduce this consistently on my Mac by setting PATH to not include Go itself. This spews lots of errors for $GOROOT/src/... in addition to the current dir's package:

$ PATH=/usr/bin:/bin:/usr/sbin:/sbin /Users/alex/.go/bin/gometalinter

But this works:

$ PATH=/usr/bin:/bin:/usr/sbin:/sbin CGO_ENABLED=0 /Users/alex/.go/bin/gometalinter

In my case, I install Go via Homebrew, and I have only one Go version installed, which lives in /usr/local/local/Cellar/go/1.9.2.

@omarkohl
Copy link

omarkohl commented Mar 9, 2018

I started getting these errors yesterday as well (latest master). But they are not reproducible and only appear sometimes.

The CGO_ENABLED=0 workaround seems to work.

@slatunje
Copy link

I came across these errors today.

In my case it was caused by custom installation by brew install go

according to Installing to a custom location go expects default to be at /usr/local/go but brew install at /usr/local/Cellar/go/1.10.1/libexec

It only works with `export GOROOT=/path/to/custom/go

fabianschwarzfritz pushed a commit to Peripli/service-broker-proxy-k8s that referenced this issue May 3, 2018
Currently the gometalinter does not work correctly with the alpine
docker image, as it scans too many directory.
See github issues:
 - kisielk/errcheck#119
 - alecthomas/gometalinter#149

As a solution, we add an additional layer with a debian image to the
multi-staged docker image. In this image, the gometalinter works
correctly.
georgifarashev pushed a commit to Peripli/service-broker-proxy-k8s that referenced this issue Jun 26, 2018
* working demo for ServiceBroker CRUD Operations

* remove unused code

* Fix formatting and lint errors

* Revert "remove unused code"

This reverts commit a01455b.

* Add Andreas example; periodically ping the service manager;

 - Add Andreas example to to a new file 'servicecatalog', which provides
 methods to list/register/unregister service brokers form the k8s
 serivce catalog.
 - Add function to periodically ping the service manager.
 - Formatting.

* Start broker proxy in main.go

* Fix constructor, check for error when setting env variable

* Use broker lib

* First working draft of k8s

* Use enablement service-manager

* Pin service-catalog to version v0.1.13

* Fix log messages in k8s client

* Proxy not needed anymore; Remove secrets/config of the k8s deployment

* Downstrip to minimal setup

* use in cluster configuration and strip down Dockerfile for friday demo.
Adding clusterrole and permissions to access the API server/servicecatalog resources.

* fix wrong service declaration - no endpoints assign regarding wrong selector

* Fix linter errors

 - Use 'envProxy' instead of 'env_proxy'
 - Add short documentation to exported methods to
 create/update/list/delete brokers in kubernetes
 - Remove not needed exports.

* Use helm for isntallation of service-broker-proxy

* Add vendor/ to SCM

Not ignoring the vendor folder eases the initial development onboarding and can
guarantee reliable builds.

* Update dependencies and pin service-broker-proxy lib to fixed version

 - Set dependencies to version of dem from last week.
 - Pin version of service-broker-proxy library do working version of
 last week.

* Fix port in service definition in helm chart

* Use gcr docker repository as the default in the helm chart

* Improve installation instructions

* Add additional docker image for gometalinter.

Currently the gometalinter does not work correctly with the alpine
docker image, as it scans too many directory.
See github issues:
 - kisielk/errcheck#119
 - alecthomas/gometalinter#149

As a solution, we add an additional layer with a debian image to the
multi-staged docker image. In this image, the gometalinter works
correctly.

* Update service-broker-proxy library.

Update service-broker-proxy library to the most recent version.
Adopt client.go to use the newest library version.

* Fix client go type error

* Improve in-code documentation.

* Improve build script for development.

Use helm to install the service-broker-proxy-k8s.

* Tests: implement tests for successfull service-broker operation.

Implement tests for successful service broker operations: create/delete/update/get/sync

* File system mock obsolete in client_internal_test

* Add go dep dependencies for ginkgo and gomega.

* Use better fake urls in unit test.

* Improve logging and log levels.

 - Use warn log-level when an error with the service-catalog occurs and return
 the error to the service-broker-proxy framework.
 - Use fatal log level when the creation of a k8s client occurs.

* Test output prints more information in docker build.

* Test service-broker-creation when catalog returns an error.

* Test service-broker-deletion when catalog returns an error.

* Test getting service-brokers when catalog returns an error.

* Test service-broker-delete when catalog returns an error.

* Test syncing service-brokers when catalog returns an error.

* Print broker guids/names with log messages

* Print go test coverage during build

* Print test coverage

Added a script to print the test coverage information with the following
outputs:
 - html report
 - stdout

* Use .html filending for coverage report

* Return error when clusterconfig cannot be loaded.

* More coverage details during Docker build

* Improve test coverage

Review with @AlexRieder:
 - use warn log-level when error with service-catalog occurs
 - Improve test for service-broker-creation
 - Add test to check getBrokers with empty list of brokers

* README badge: Add go report and add branch to coveralls

* No error handling, as log.Fatal exists the program

* Log error and return error when configuration cannot be loaded

* Template values for service-manager-instance
@yuroyoro
Copy link

yuroyoro commented Sep 25, 2018

I've faced same error on go 1.11 and gometelinter 0.2.1
I think the root cause of this problem is gometelinter set the $GOROOT environment variable when it is not set.
(It was introduced at 0725fc6)

For example, give $GOROOT to gotype, it reports same errors.
when no $GOROOT given, the gotype report nothing.

run gotype via gometelinter:

$ gometalinter --disable-all -d --enable=gotype

DEBUG: [Sep 25 08:52:43.534] GOPATH="/home/ozaki/dev/go"
DEBUG: [Sep 25 08:52:43.534] GOBIN=""
DEBUG: [Sep 25 08:52:43.534] GOROOT="/usr/lib/go-1.11"
DEBUG: [Sep 25 08:52:43.539] [gotype.1]: executing /home/ozaki/dev/go/bin/gotype -e .
DEBUG: [Sep 25 08:52:43.969] [gotype.1]: warning: /home/ozaki/dev/go/bin/gotype returned exit status 2: main.go:4:2: could not import encoding/csv (type-checking package "encoding/csv" failed (/usr/lib/go-1.11/src/encoding/csv/reader.go:55:2: could not import bufio (type-checking package "bufio" failed (/usr/lib/go-1.11/src/bufio/bufio.go:11:2: could not import bytes (type-checking package "bytes" failed (/usr/lib/go-1.11/src/bytes/buffer.go:11:2: could not import io (type-checking package "io" failed (/usr/lib/go-1.11/src/io/pipe.go:12:2: could not import sync (type-checking package "sync" failed (/usr/lib/go-1.11/src/sync/pool.go:9:2: could not import runtime (type-checking package "runtime" failed (/usr/lib/go-1.11/src/runtime/alg.go:8:2: could not import internal/cpu (type-checking package "internal/cpu" failed (/usr/lib/go-1.11/src/internal/cpu/cpu_x86.go:9:7: CacheLinePadSize redeclared in this block))))))))))))))

run gotype directly without GOROOT, it's no errors reported.

$ /home/ozaki/dev/go/bin/gotype -e -v .
main.go
207.729659ms (1 files, 50 lines, 240 lines/s)

run gotype directly with GOROOT, same errors are reproduced.

$ GOROOT="/usr/lib/go-1.11" /home/ozaki/dev/go/bin/gotype -e -v .
main.go
main.go:4:2: could not import encoding/csv (type-checking package "encoding/csv" failed (/usr/lib/go-1.11/src/encoding/csv/reader.go:55:2: could not import bufio (type-checking package "bufio" failed (/usr/lib/go-1.11/src/bufio/bufio.go:11:2: could not import bytes (type-checking package "bytes" failed (/usr/lib/go-1.11/src/bytes/buffer.go:11:2: could not import io (type-checking package "io" failed (/usr/lib/go-1.11/src/io/pipe.go:12:2: could not import sync (type-checking package "sync" failed (/usr/lib/go-1.11/src/sync/pool.go:9:2: could not import runtime (type-checking package "runtime" failed (/usr/lib/go-1.11/src/runtime/alg.go:8:2: could not import internal/cpu (type-checking package "internal/cpu" failed (/usr/lib/go-1.11/src/internal/cpu/cpu_x86.go:9:7: CacheLinePadSize redeclared in this block))))))))))))))

After Go 1.10, the $GOROOT should not be set.
You don’t need to set GOROOT, really | Dave Cheney

zzak pushed a commit to CircleCI-Public/circleci-cli that referenced this issue Dec 3, 2018
Thanks to @dnephin who already solved this for us over a year ago:
alecthomas/gometalinter#149 (comment)
@johanbrandhorst
Copy link

johanbrandhorst commented Feb 27, 2019

Seeing this after upgrading to Go 1.12, not sure why. Disabling CGO did not seem to help. Still investigating what caused it.

EDIT: this is with gometalinter version 2.0.11.

EDIT2: Same error on 3.0.0, however, using the following configuration seems to help gometalinter.json:

{
    "Exclude": ["/usr/local/go/src", "/go/src"]
}

Seems a workaround more than a fix though.

@Dynom
Copy link
Author

Dynom commented Feb 27, 2019

Try switching to golangci-lint instead. The Gometalinter project is (nearing) EOL.

hkz-aarvesen added a commit to lostromos/lostromos that referenced this issue Mar 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.