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

tenv: package "..." (isInitialPkg: true, needAnalyzeSource: true): runtime error: index out of range [0] with length 0 #2986

Closed
4 tasks done
bflad opened this issue Jul 18, 2022 · 1 comment · Fixed by #2988
Labels
bug Something isn't working dependencies Relates to an upstream dependency

Comments

@bflad
Copy link
Contributor

bflad commented Jul 18, 2022

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

Our GitHub Actions workflow using golangci-lint-action automatically upgrading from 1.46.2 to 1.47.0 today and began receiving tenv linter panics:

ERRO [runner] Panic: tenv: package "terraform" (isInitialPkg: true, needAnalyzeSource: true): runtime error: index out of range [0] with length 0: goroutine 9468 [running]:
runtime/debug.Stack()
	runtime/debug/stack.go:24 +0x68
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func1()
	github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:101 +0x104
panic({0x10599a1e0, 0x140008bbaa0})
	runtime/panic.go:838 +0x204
github.com/sivchari/tenv.targetRunner({0x14009ca09d8, 0x1, 0x1?}, {0x14000c67260, 0x55})
	github.com/sivchari/tenv@v1.6.0/tenv.go:166 +0x3e0
github.com/sivchari/tenv.checkFuncLit(0x14000c1dc40?, 0x1400a2311c0, {0x14000c67260?, 0x104b463e4?})
	github.com/sivchari/tenv@v1.6.0/tenv.go:62 +0x54
github.com/sivchari/tenv.run.func1({0x105a079f0?, 0x1400a2311c0?})
	github.com/sivchari/tenv@v1.6.0/tenv.go:46 +0xfc
golang.org/x/tools/go/ast/inspector.(*Inspector).Preorder(0x14005a5ab40, {0x140048f9ce8?, 0x2?, 0x30000007d?}, 0x1400834bcd8)
	golang.org/x/tools@v0.1.11/go/ast/inspector/inspector.go:77 +0xac
github.com/sivchari/tenv.run(0x14008a5dc70)
	github.com/sivchari/tenv@v1.6.0/tenv.go:41 +0xa0
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyze(0x14002faaf70)
	github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:187 +0x96c
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func2()
	github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:105 +0x24
github.com/golangci/golangci-lint/pkg/timeutils.(*Stopwatch).TrackStage(0x14000e0fae0, {0x105531ca0, 0x4}, 0x140018a4f30)
	github.com/golangci/golangci-lint/pkg/timeutils/stopwatch.go:111 +0x48
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe(0x1050c2bf0?)
	github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:104 +0x78
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze.func2(0x14002faaf70)
	github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_loadingpackage.go:80 +0xb4
created by github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze
	github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_loadingpackage.go:75 +0x16c
WARN [runner] Can't run linter goanalysis_metalinter: goanalysis_metalinter: tenv: package "terraform" (isInitialPkg: true, needAnalyzeSource: true): runtime error: index out of range [0] with length 0
ERRO Running error: 1 error occurred:
	* can't run linter goanalysis_metalinter: goanalysis_metalinter: tenv: package "terraform" (isInitialPkg: true, needAnalyzeSource: true): runtime error: index out of range [0] with length 0

It appears that there was a tenv release a few minutes ago, 1.7.0, that may fix this issue.

Version of golangci-lint

$ golangci-lint --version
# Paste output here

Configuration file

$ cat .golangci.yml
issues:
  exclude-rules:
    - linters:
        - staticcheck
      text: 'SA1019: schema.SchemaValidateFunc is deprecated'
  max-per-linter: 0
  max-same-issues: 0

linters:
  disable-all: true
  enable:
    - deadcode
    - durationcheck
    - errcheck
    - exportloopref
    - gofmt
    - gosimple
    - ineffassign
    - makezero
    - nilerr
    # - paralleltest # Reference: https://github.com/kunwardeep/paralleltest/issues/14
    - predeclared
    - staticcheck
    - tenv
    - unconvert
    - unparam
    - varcheck
    - vet

Go environment

$ go version && go env
go version go1.18.4 darwin/arm64

GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/bflad/Library/Caches/go-build"
GOENV="/Users/bflad/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/bflad/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/bflad/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/opt/homebrew/Cellar/go/1.18.4/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/homebrew/Cellar/go/1.18.4/libexec/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.18.4"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/bflad/src/github.com/hashicorp/terraform-plugin-sdk/go.mod"
GOWORK=""
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/f3/2mhr8hkx72z9dllv0ry81zm40000gq/T/go-build337737696=/tmp/go-build -gno-record-gcc-switches -fno-common"

Verbose output of running

$ golangci-lint cache clean
$ golangci-lint run -v
INFO [config_reader] Config search paths: [./ /Users/bflad/src/github.com/hashicorp/terraform-plugin-sdk /Users/bflad/src/github.com/hashicorp /Users/bflad/src/github.com /Users/bflad/src /Users/bflad /Users /]
INFO [config_reader] Used config file .golangci.yml
INFO [lintersdb] Active 16 linters: [deadcode durationcheck errcheck exportloopref gofmt gosimple govet ineffassign makezero nilerr predeclared staticcheck tenv unconvert unparam varcheck]
INFO [loader] Go packages loading at mode 575 (deps|imports|name|compiled_files|exports_file|files|types_sizes) took 351.031333ms
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 21.752834ms
INFO [linters context/goanalysis] analyzers took 17.033351283s with top 10 stages: buildir: 8.132084959s, buildssa: 695.988918ms, inspect: 634.93296ms, fact_deprecated: 626.779867ms, gofmt: 524.198252ms, ctrlflow: 456.088333ms, printf: 440.84042ms, nilness: 360.298125ms, fact_purity: 346.400131ms, S1038: 255.319334ms
ERRO [runner] Panic: tenv: package "terraform" (isInitialPkg: true, needAnalyzeSource: true): runtime error: index out of range [0] with length 0: goroutine 8526 [running]:
runtime/debug.Stack()
	runtime/debug/stack.go:24 +0x68
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func1()
	github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:101 +0x104
panic({0x10553e1e0, 0x1400bcbeff0})
	runtime/panic.go:838 +0x204
github.com/sivchari/tenv.targetRunner({0x1400d33f390, 0x1, 0x1?}, {0x14000cb9200, 0x55})
	github.com/sivchari/tenv@v1.6.0/tenv.go:166 +0x3e0
github.com/sivchari/tenv.checkFuncLit(0x14000c63bc0?, 0x1400a641120, {0x14000cb9200?, 0x1046ea3e4?})
	github.com/sivchari/tenv@v1.6.0/tenv.go:62 +0x54
github.com/sivchari/tenv.run.func1({0x1055ab9f0?, 0x1400a641120?})
	github.com/sivchari/tenv@v1.6.0/tenv.go:46 +0xfc
golang.org/x/tools/go/ast/inspector.(*Inspector).Preorder(0x1400e306a20, {0x140009f04e8?, 0x2?, 0x30000007d?}, 0x140040bdcd8)
	golang.org/x/tools@v0.1.11/go/ast/inspector/inspector.go:77 +0xac
github.com/sivchari/tenv.run(0x1400261e820)
	github.com/sivchari/tenv@v1.6.0/tenv.go:41 +0xa0
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyze(0x14002c88f70)
	github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:187 +0x96c
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func2()
	github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:105 +0x24
github.com/golangci/golangci-lint/pkg/timeutils.(*Stopwatch).TrackStage(0x140010aecd0, {0x1050d5ca0, 0x4}, 0x140009f0730)
	github.com/golangci/golangci-lint/pkg/timeutils/stopwatch.go:111 +0x48
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe(0x104c66bf0?)
	github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:104 +0x78
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze.func2(0x14002c88f70)
	github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_loadingpackage.go:80 +0xb4
created by github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze
	github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_loadingpackage.go:75 +0x16c
WARN [runner] Can't run linter goanalysis_metalinter: goanalysis_metalinter: tenv: package "terraform" (isInitialPkg: true, needAnalyzeSource: true): runtime error: index out of range [0] with length 0
INFO [runner] processing took 2.957µs with stages: max_same_issues: 875ns, nolint: 416ns, max_from_linter: 333ns, skip_files: 167ns, autogenerated_exclude: 167ns, skip_dirs: 166ns, filename_unadjuster: 125ns, exclude: 125ns, path_prettifier: 84ns, severity-rules: 84ns, cgo: 83ns, path_prefixer: 42ns, uniq_by_line: 42ns, exclude-rules: 42ns, max_per_file_from_linter: 42ns, identifier_marker: 41ns, sort_results: 41ns, diff: 41ns, path_shortener: 41ns, source_code: 0s
INFO [runner] linters took 2.62459925s with stages: goanalysis_metalinter: 2.62456525s
ERRO Running error: 1 error occurred:
	* can't run linter goanalysis_metalinter: goanalysis_metalinter: tenv: package "terraform" (isInitialPkg: true, needAnalyzeSource: true): runtime error: index out of range [0] with length 0

INFO Memory: 32 samples, avg is 394.3MB, max is 571.2MB
INFO Execution took 3.007861333s

Code example or link to a public repository

https://github.com/hashicorp/terraform-plugin-sdk/runs/7394086947?check_suite_focus=true

@bflad bflad added the bug Something isn't working label Jul 18, 2022
@bflad
Copy link
Contributor Author

bflad commented Jul 18, 2022

I can confirm bumping the tenv version fixes the issue:

# In golangci-lint codebase
go get github.com/sivchari/tenv@v1.7.0
go mod tidy
go install ./cmd/golangci-lint

# In affected codebase
~/go/bin/golangci-lint run
# ... runs successfully without panic ...

@ldez ldez added the dependencies Relates to an upstream dependency label Jul 18, 2022
@ldez ldez changed the title New 1.47.0 Panic: tenv: package "..." (isInitialPkg: true, needAnalyzeSource: true): runtime error: index out of range [0] with length 0 tenv: package "..." (isInitialPkg: true, needAnalyzeSource: true): runtime error: index out of range [0] with length 0 Jul 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working dependencies Relates to an upstream dependency
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants