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

Panic since update to v1.43.0 (load embedded ruleguard rules: rules/rules.go:13: can't load fmt) #2374

Closed
4 tasks done
Antonboom opened this issue Nov 23, 2021 · 28 comments · Fixed by openshift/configuration-anomaly-detection#33
Assignees
Labels
bug Something isn't working

Comments

@Antonboom
Copy link
Contributor

Antonboom commented Nov 23, 2021

Welcome

  • Yes, I'm using a binary release within 2 latest major releases. Only such installations are supported.
  • Yes, I've searched similar issues on GitHub and didn't find any.
  • Yes, I've included all information below (version, config, etc).
  • Yes, I've tried with the standalone linter if available. (https://golangci-lint.run/usage/linters/)

Description of the problem

Please read

go-critic/go-critic#1157

Version of golangci-lint

$ golangci-lint --version
panic: load embedded ruleguard rules: rules/rules.go:13: can't load fmt

goroutine 1 [running]:
github.com/go-critic/go-critic/checkers.init.9()
        github.com/go-critic/go-critic@v0.6.1/checkers/checkers.go:58 +0x4b4

Configuration file

No file.

Go environment

$ go version && go env
go version go1.17.1 darwin/arm64
GO111MODULE="on"
GOARCH="arm64"
GOBIN="/Users/anthony/golang_workspace/bin"
GOCACHE="/Users/anthony/Library/Caches/go-build"
GOENV="/Users/anthony/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/anthony/golang_workspace/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/anthony/golang_workspace"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.17.1"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/anthony/****/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/6t/v80c8sfs5zqf38b2yhzq592h0000gn/T/go-build1630597575=/tmp/go-build -gno-record-gcc-switches -fno-common"

Verbose output of running

$ golangci-lint cache clean
panic: load embedded ruleguard rules: rules/rules.go:13: can't load fmt

goroutine 1 [running]:
github.com/go-critic/go-critic/checkers.init.9()
        github.com/go-critic/go-critic@v0.6.1/checkers/checkers.go:58 +0x4b4


$ golangci-lint run -v
panic: load embedded ruleguard rules: rules/rules.go:13: can't load fmt

goroutine 1 [running]:
github.com/go-critic/go-critic/checkers.init.9()
        github.com/go-critic/go-critic@v0.6.1/checkers/checkers.go:58 +0x4b4
@Antonboom Antonboom added bug Something isn't working dependencies Relates to an upstream dependency labels Nov 23, 2021
@Antonboom Antonboom changed the title Panic after upgrade golangci-lint to v1.43.0 (load embedded ruleguard rules: rules/rules.go:13: can't load fmt) Panic since update to v1.43.0 (load embedded ruleguard rules: rules/rules.go:13: can't load fmt) Nov 23, 2021
@Antonboom
Copy link
Contributor Author

Antonboom commented Nov 25, 2021

TL;DR

  • check what your Go is for ARM
  • check env (go version & GOARCH) in IDEA
  • do not install golangci-lint via brew

I decided to compare the output of go env in IDEA & zsh:

$ diff /tmp/idea.env /tmp/zsh.env
1,2c1,2
< GO111MODULE=""
< GOARCH="amd64"
---
> GO111MODULE="on"
> GOARCH="arm64"
9c9
< GOHOSTARCH="amd64"
---
> GOHOSTARCH="arm64"
22c22
< GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
---
> GOTOOLDIR="/usr/local/go/pkg/tool/darwin_arm64"
24c24
< GOVERSION="go1.17.2"
---
> GOVERSION="go1.17.1"
37c37
< GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/6t/v80c8sfs5zqf38b2yhzq592h0000gn/T/go-build2865944367=/tmp/go-build -gno-record-gcc-switches -fno-common"
\ No newline at end of file
---
> GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/6t/v80c8sfs5zqf38b2yhzq592h0000gn/T/go-build3978166248=/tmp/go-build -gno-record-gcc-switches -fno-common"

Two questions:

  1. why different archs (amd & arm)?
  2. why different Go versions (1.17.2 & 1.17.1)?

I didn't remember installing multiple versions of Go. This IDEA project was new & he picked up the environment automatically. And it was:

$ /usr/local/Cellar/go/1.17.2/bin/go env
GO111MODULE="on"
GOARCH="amd64"
...
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
...
GOOS="darwin"
...
GOROOT="/usr/local/go"         <----------------------- WTF? It's a path of original 1.17.1 ARM Go
...
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GOVERSION="go1.17.2"
...

That's where the dog is buried. 1.17.2 AMD Go flew in together with new golangci-lint:

$ brew install golangci-lint
==> Downloading https://ghcr.io/v2/homebrew/core/go/manifests/1.17.2
...
==> Installing dependencies for golangci-lint: go
==> Installing golangci-lint dependency: go
==> Pouring go--1.17.2.big_sur.bottle.tar.gz
🍺  /usr/local/Cellar/go/1.17.2: 10,814 files, 565.8MB
==> Installing golangci-lint
...

Solution:

$ golangci-lint version
golangci-lint has version 1.43.0 built from 861262b7 on 2021-11-03T11:57:46Z

$ golangci-lint run ./...
$?                    
zsh: command not found: 0

@ldez, FYI
You can close this issue & open other about brew. leave it to you, thanks!

@Antonboom Antonboom removed the dependencies Relates to an upstream dependency label Nov 25, 2021
@ldez ldez self-assigned this Nov 25, 2021
@atc0005

This comment has been minimized.

@ldez
Copy link
Member

ldez commented Dec 15, 2021

go1.18beta1 is currently not supported by golangci-lint.

I flag this as off-topic for now.

@quasilyte

This comment has been minimized.

@ldez

This comment has been minimized.

@willbeason
Copy link

The comments marked as "off topic" resolved my issue for me when I encountered this. My build environment was updated to 1.18 automatically, so this upgrade broke golangci-lint for me. Thus, I had to build from source in order to resolve the issue.

@quasilyte
Copy link
Contributor

quasilyte commented Jan 19, 2022

@willbeason please keep in mind that this new release is an unknown ground for most of us.
For many maintainers of any kinds of linters it's hard to adapt before 1.18 is released completely.
It's like living in two realities, etc.
Not to mention that there are some issues in the relevant libraries like /x/tools that make the transition hard (most tools rely on them in one way or another).
While building from the source may be helpful, it also means the issue in the underlying tools we're using to bundle our tools. Which is another hint that the main issue may not be on the side of the maintainers (they can't update the world, etc.)

So let's try to be patient. This is a big release for Go.

mtrmac added a commit to mtrmac/image that referenced this issue Mar 15, 2022
This is an attempt to fix (make lint), which complains:
> pkg/tlsclientconfig/tlsclientconfig_test.go:37:20: SA1019: tlsc.RootCAs.Subjects is deprecated: if s was returned by SystemCertPool, Subjects will not include the system roots. (staticcheck)
>       for _, s := range tlsc.RootCAs.Subjects() {
>                         ^
> pkg/tlsclientconfig/tlsclientconfig_test.go:43:20: SA1019: systemCertPool.Subjects is deprecated: if s was returned by SystemCertPool, Subjects will not include the system roots. (staticcheck)
>       for _, s := range systemCertPool.Subjects() {
>                         ^
> pkg/tlsclientconfig/tlsclientconfig_test.go:53:20: SA1019: tlsc.RootCAs.Subjects is deprecated: if s was returned by SystemCertPool, Subjects will not include the system roots. (staticcheck)
>       for _, s := range tlsc.RootCAs.Subjects() {

... but the same staticcheck linter, for some reason, does NOT
complain about these deprecated fields; the correct //lint:ignore
comments are ineffective and actually cause extra warnings.

So, silence all of staticcheck via //nolint , hopefully temporarily.

(Also, note that golangci-lint itself, with this update,
crashes with golangci/golangci-lint#2374 ;
a local rebuild does not crash, but still fails per the above.)

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
@oneumyvakin
Copy link

I'm not sure how to update x/tool because our project has a lot of packages which have multiple transitive dependencies on old x/tools

Here the debug output:

#10 [5/5] RUN gofmt -d $(find . -type f -name '*.go' -not -path "./vendor/*") &&     golangci-lint run &&     go test -mod=vendor -cover ./... &&     go build -mod=vendor
#10 sha256:23794d00eb35d59d177437edfb5f4b1ecc1941264a992a7c6130cdf1fdfc1875
#10 5.329 debug: failed to import "fmt":
#10 5.329 debug:   gc importer: can't find import: "fmt"
#10 5.329 debug:   source importer: type-checking package "fmt" failed (/usr/local/go/src/fmt/errors.go:7:8: could not import errors (type-checking package "errors" failed (/usr/local/go/src/errors/wrap.go:8:2: could not import internal/reflectlite (type-checking package "internal/reflectlite" failed (/usr/local/go/src/internal/reflectlite/value.go:10:2: could not import runtime (type-checking package "runtime" failed (/usr/local/go/src/runtime/chan.go:21:2: could not import internal/abi (type-checking package "internal/abi" failed (/usr/local/go/src/internal/abi/abi.go:117:19: undeclared name: any)))))))))
#10 5.329 debug:   GOROOT="/usr/local/go" GOPATH="/go"
#10 9.796 debug: failed to import "fmt":
#10 9.796 debug:   gc importer: can't find import: "fmt"
#10 9.796 debug:   source importer: type-checking package "fmt" failed (/usr/local/go/src/fmt/errors.go:7:8: could not import errors (type-checking package "errors" failed (/usr/local/go/src/errors/wrap.go:8:2: could not import internal/reflectlite (type-checking package "internal/reflectlite" failed (/usr/local/go/src/internal/reflectlite/value.go:10:2: could not import runtime (type-checking package "runtime" failed (/usr/local/go/src/runtime/chan.go:21:2: could not import internal/abi (type-checking package "internal/abi" failed (/usr/local/go/src/internal/abi/abi.go:117:19: undeclared name: any)))))))))
#10 9.796 debug:   GOROOT="/usr/local/go" GOPATH="/go"
#10 9.798 panic: load embedded ruleguard rules: rules/rules.go:13: can't load fmt
#10 9.798 
#10 9.798 goroutine 1 [running]:
#10 9.798 github.com/go-critic/go-critic/checkers.init.22()
#10 9.798 	github.com/go-critic/go-critic@v0.6.2/checkers/embedded_rules.go:46 +0x4b4
#10 ERROR: executor failed running [/bin/sh -c gofmt -d $(find . -type f -name '*.go' -not -path "./vendor/*") &&     golangci-lint run &&     go test -mod=vendor -cover ./... &&     go build -mod=vendor]: exit code: 2

@mikkeloscar
Copy link

Installing golangci-lint from source I don't observe the same error as when using the released binary.

Binary

wget https://github.com/golangci/golangci-lint/releases/download/v1.44.2/golangci-lint-1.44.2-linux-amd64.tar.gz
tar -xf golangci-lint-1.44.2-linux-amd64.tar.gz
./golangci-lint-1.44.2-linux-amd64/golangci-lint --version
panic: load embedded ruleguard rules: rules/rules.go:13: can't load fmt

Install from source

go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.44.2

golangci-lint --version
golangci-lint has version v1.44.2 built from (unknown, mod sum: "h1:MzvkDt1j1OHkv42/feNJVNNXRFACPp7aAWBWDo5aYQw=") on (unknown)

@ldez
Copy link
Member

ldez commented Mar 16, 2022

If you are using go1.18, please follow the issue #2649

@ldez
Copy link
Member

ldez commented Aug 17, 2022

can you try to set explicitly the GOROOT?

@shakibamoshiri
Copy link

you can test it with this docker file

first

# golangci-lint does not work with latest version
FROM golang:latest

# use a match version
# FROM golang:1.18.3

ARG GO_LINT_ADDRESS=https://github.com/golangci/golangci-lint/releases/download/v1.46.2/golangci-lint-1.46.2-linux-amd64.tar.gz
ARG LINT_TAR_NAME=golangci-lint-1.46.2-linux-amd64

RUN apt update && \
    wget -c ${GO_LINT_ADDRESS} -O ${LINT_TAR_NAME}.tar.gz && \
    tar xzf ${LINT_TAR_NAME}.tar.gz --strip-components=1  -C /usr/bin/ ${LINT_TAR_NAME}/golangci-lint && \
    chmod +x /usr/bin/golangci-lint


# install golangci-ci by go did not work
# it runs but on runtime throws errors
# go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.46.2

CMD golangci-lint

second

docker build --no-cache -t lint:v1 .

third - result for me

Successfully built a04e027eb69d
Successfully tagged lint:v1
root[1][0]docker:/opt/prod/lint# docker run --rm -it lint:v1 
panic: load embedded ruleguard rules: rules/rules.go:13: can't load fmt

goroutine 1 [running]:
github.com/go-critic/go-critic/checkers.init.22()
	github.com/go-critic/go-critic@v0.6.3/checkers/embedded_rules.go:47 +0x4b4

@ldez
Copy link
Member

ldez commented Aug 17, 2022

can you add this GOROOT="/usr/local/go" explicitly in your Dockerfile?

(I already tried)

@ldez
Copy link
Member

ldez commented Aug 17, 2022

closed in favor of #3107

@ldez ldez closed this as completed Aug 17, 2022
damemi added a commit to damemi/descheduler that referenced this issue Sep 6, 2022
eranco74 added a commit to eranco74/cluster-api-provider-agent that referenced this issue Sep 19, 2022
eranco74 added a commit to eranco74/cluster-api-provider-agent that referenced this issue Sep 19, 2022
eranco74 added a commit to eranco74/cluster-api-provider-agent that referenced this issue Sep 19, 2022
eranco74 added a commit to eranco74/cluster-api-provider-agent that referenced this issue Sep 19, 2022
eranco74 added a commit to eranco74/cluster-api-provider-agent that referenced this issue Sep 19, 2022
openshift-merge-robot pushed a commit to openshift/cluster-api-provider-agent that referenced this issue Sep 19, 2022
* go 1.17 has deprecated installing executables with `go get`
Use go install instead
Set GOFLAGS to empty string to overcome the `cannot query module due to
-mod=vendor` error we get in presubmit job

* Updated kustomize version to a version that support go install
See kubernetes-sigs/kustomize#3618

* Install golangci-lint from source
See golangci/golangci-lint#2374

* Fix lint issue
See golangci/golangci-lint#2601

* Refactor - don't pass around origRes and origErr
adracus added a commit to ironcore-dev/metalnet that referenced this issue Oct 12, 2022
This should resolve some of the `golangci-lint` issues that arose due to
go1.19, see
* golangci/golangci-lint#2374
* golangci/golangci-lint#3037
kyrylo added a commit to airbrake/gobrake that referenced this issue Jan 10, 2023
v1.44.2 contains a bug:

```
panic: load embedded ruleguard rules: rules/rules.go:13: can't load fmt
```

golangci/golangci-lint#2374
Itxaka pushed a commit to kairos-io/kairos-agent that referenced this issue Apr 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.