go-critic: panic in load embedded ruleguard rules: can't load fmt
I was trying out the latest v0.6.0 (https://github.com/go-critic/go-critic/releases/tag/v0.6.0) on Windows and it failed with:
> gocritic ./...
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()
/home/isharipov/CODE/go-critic3/checkers/checkers.go:47 +0x3b4
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 44 (21 by maintainers)
Commits related to this issue
- ruleguard: prefer `importer.Default()` to "source" importer See https://github.com/go-critic/go-critic/issues/1126 Using `importer.Default()` is not going to play well with `$GOPATH` relying install... — committed to quasilyte/go-ruleguard by quasilyte 3 years ago
- all: overcoming srcimporter issues See https://github.com/go-critic/go-critic/issues/1126 We're using the host-specific `go env` info to avoid incorrect GOROOT and other Go build context variables. — committed to quasilyte/go-ruleguard by quasilyte 3 years ago
- all: overcoming srcimporter issues See https://github.com/go-critic/go-critic/issues/1126 We're using the host-specific `go env` info to avoid incorrect GOROOT and other Go build context variables. — committed to quasilyte/go-ruleguard by quasilyte 3 years ago
- all: overcoming srcimporter issues See https://github.com/go-critic/go-critic/issues/1126 We're using the host-specific `go env` info to avoid incorrect GOROOT and other Go build context variables. — committed to quasilyte/go-ruleguard by quasilyte 3 years ago
- all: overcoming srcimporter issues See https://github.com/go-critic/go-critic/issues/1126 We're using the host-specific `go env` info to avoid incorrect GOROOT and other Go build context variables. — committed to quasilyte/go-ruleguard by quasilyte 3 years ago
- all: overcoming srcimporter issues See https://github.com/go-critic/go-critic/issues/1126 We're using the host-specific `go env` info to avoid incorrect GOROOT and other Go build context variables. — committed to quasilyte/go-ruleguard by quasilyte 3 years ago
- all: overcoming srcimporter issues See https://github.com/go-critic/go-critic/issues/1126 We're using the host-specific `go env` info to avoid incorrect GOROOT and other Go build context variables. — committed to quasilyte/go-ruleguard by quasilyte 3 years ago
- all: overcoming srcimporter issues See https://github.com/go-critic/go-critic/issues/1126 We're using the host-specific `go env` info to avoid incorrect GOROOT and other Go build context variables. — committed to quasilyte/go-ruleguard by quasilyte 3 years ago
- all: overcoming srcimporter issues See https://github.com/go-critic/go-critic/issues/1126 We're using the host-specific `go env` info to avoid incorrect GOROOT and other Go build context variables. — committed to quasilyte/go-ruleguard by quasilyte 3 years ago
- all: overcoming srcimporter issues (#288) See https://github.com/go-critic/go-critic/issues/1126 We're using the host-specific `go env` info to avoid incorrect GOROOT and other Go build context v... — committed to quasilyte/go-ruleguard by quasilyte 3 years ago
- update go-ruleguard The newer version uses a fix for srcimporter that tries to use host GOROOT and then fails to locate stdlib packages. Updates #1126 — committed to go-critic/go-critic by quasilyte 3 years ago
- update go-ruleguard The newer version uses a fix for srcimporter that tries to use incorrect GOROOT and then fails to locate stdlib packages. Updates #1126 — committed to go-critic/go-critic by quasilyte 3 years ago
- update go-ruleguard (#1132) The newer version uses a fix for srcimporter that tries to use incorrect GOROOT and then fails to locate stdlib packages. Updates #1126 — committed to go-critic/go-critic by quasilyte 3 years ago
- go.mod: upgrade go-ruleguard to v0.3.13 The previous upgrade (v0.3.12) fixed Linux and Darwin release binaries, but not Windows binaries. The issue was related to a fact that `go env` has a differen... — committed to go-critic/go-critic by quasilyte 3 years ago
- go.mod: upgrade go-ruleguard to v0.3.13 (#1138) The previous upgrade (v0.3.12) fixed Linux and Darwin release binaries, but not Windows binaries. The issue was related to a fact that `go env` has... — committed to go-critic/go-critic by quasilyte 3 years ago
- * golangci-lint v1.44.2 * Add check action * Remove gocritic due to https://github.com/go-critic/go-critic/issues/1126 Signed-off-by: Anders Eknert <anders@eknert.com> — committed to anderseknert/kube-review by anderseknert 2 years ago
- Fix linting * golangci-lint v1.44.2 * Add check action * Remove gocritic due to https://github.com/go-critic/go-critic/issues/1126 Signed-off-by: Anders Eknert <anders@eknert.com> — committed to anderseknert/kube-review by anderseknert 2 years ago
- Fix linting * golangci-lint v1.44.2 * Add check action * Remove gocritic due to https://github.com/go-critic/go-critic/issues/1126 Signed-off-by: Anders Eknert <anders@eknert.com> — committed to anderseknert/kube-review by anderseknert 2 years ago
- Fix linting * golangci-lint v1.44.2 * Add check action * Remove gocritic due to https://github.com/go-critic/go-critic/issues/1126 Signed-off-by: Anders Eknert <anders@eknert.com> — committed to anderseknert/kube-review by anderseknert 2 years ago
Digging a bit deeper, this is not really the same issue, but just incompatibility with Go 1.18 while trying to load the source files.
Is this worth opening a new issue for, or should I just consider new Go versions unsupported until there’s a new go-critic release (that probably needs to be compiled with the new Go version so the type-checking works correctly)?
In the interim, it might make sense to remove the pre-built release binaries and recommend building from source.
So I’ve been debugging a bit:
It looks like
GOROOT
of the compilation location is being used due to a call to https://pkg.go.dev/go/importer#ForCompiler (in https://github.com/quasilyte/go-ruleguard/blob/84a8b0bc91ee08ce7c77baf5214dea1bc403ea34/ruleguard/importer.go#L45). Effectively, it tries to useGOROOT
of the computer doing the building. Not sure what the fix is yet though.Can confirm it works for me with the go-ruleguard update.
Looks like ruleguard uses go/importer somewhat incorrectly. I’m trying to figure out how to address that.
I tried building the latest gocritic for windows in a linux container and running it. It does seem to run fine, but, I also didn’t do any extensive testing. The issue can always be reopened when someone encounters an issue.
@egonelbre hmm, I knew about
go env VAR
syntax, but didn’t know that it supports a list of vars. Good to know, thank you! I’m learning new things every day with you. 😃Yes, it outputs things to set the environment variable by default. You can use
go env GOPATH GOROOT GOOS GOARCH
to get the specific values.If I compile it from source then it works fine.
Sidenote:
go generate ./...
doesn’t work on tip.Note,
gocritic check ./...
fails with the same error.