Open
Description
The issue is a kind of documentation about this topic.
Description of the problem
- Before v1.49.0, the load of the
ruleguard
(go-critic
) rules happens in aninit()
function and through a panic if there is a problem (I will explain the problem after).
$ golangci-lint run
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/[email protected]/checkers/checkers.go:58 +0x4b4
- After v1.49.0, the load of the
ruleguard
(go-critic
) rules happens only when go-critic is enabled, and it will produce a simple error. From my experience, the error should disappear with this release due to changes insideruleguard
andgo-critic
.
$ golangci-lint run
[ERROR] go-critic: load embedded ruleguard rules: rules/rules.go:13: can't load fmt: setting an explicit GOROOT can fix this problem.
The problem
The error happens only when ruleguard
(go-critic
) is not able to load rules.
ruleguard
(go-critic
) uses GOROOT
to load rules.
If the value of GOROOT
is empty, ruleguard
will fallback to the GOROOT
from the Go context but this Go context can be wrong.
go-critic issues
- panic in load embedded ruleguard rules: can't load fmt go-critic/go-critic#1126
- Panic after upgrade golangci-lint to v1.43.0 go-critic/go-critic#1157
- panic under Go 1.18 go-critic/go-critic#1210 (duplicate)
- Support generics for Go 1.18 go-critic/go-critic#1193 (duplicate)
- Transform
init
function inembedded_rules.go
to an exported function go-critic/go-critic#1218
Previous issues
- go1.17 arm64 fails with can't load fmt error (>= 1.45.0) #2673
- Panic since update to v1.43.0 (load embedded ruleguard rules: rules/rules.go:13: can't load fmt) #2374
- go1.17 arm64 fails with can't load fmt error (>= 1.45.0) #2673
- go-critic/ruleguard: compatibility with Go 1.18 #2414
- go-critic: checkers.init panic with go1.19beta1 #2922
- Go 1.19 panic: can't load fmt #3057
- Panics with go1.19 #3053
The solution?
To avoid this problem you can define explicitly the GOROOT
environment variable.
$ go env GOROOT
/usr/local/go
$ export GOROOT=/usr/local/go
# or
export "GOROOT=$(go env GOROOT)"