Skip to content

Panic when running promlinter #2222

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

Closed
4 tasks done
rleungx opened this issue Sep 6, 2021 · 7 comments · Fixed by #2500
Closed
4 tasks done

Panic when running promlinter #2222

rleungx opened this issue Sep 6, 2021 · 7 comments · Fixed by #2500
Labels
bug Something isn't working dependencies Relates to an upstream dependency

Comments

@rleungx
Copy link
Contributor

rleungx commented Sep 6, 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

> golangci-lint -E promlinter run ./...
ERRO [runner] Panic: promlinter: package "main" (isInitialPkg: true, needAnalyzeSource: true): runtime error: index out of range [0] with length 0: goroutine 24098 [running]:
runtime/debug.Stack(0x166a054, 0x3c, 0xc002f58750)
	/usr/lib/golang/src/runtime/debug/stack.go:24 +0x9f
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func1(0xc003d888d0)
	/xxx/go/pkg/mod/github.com/golangci/[email protected]/pkg/golinters/goanalysis/runner_action.go:101 +0x1be
panic(0x152f060, 0xc002a28060)
	/usr/lib/golang/src/runtime/panic.go:965 +0x1b9
github.com/yeya24/promlinter.(*visitor).parseCallerExpr(0xc0188125c0, 0xc016a5a080, 0x17cbb00, 0x0)
	/xxx/go/pkg/mod/github.com/yeya24/[email protected]/promlinter.go:253 +0xaaf
github.com/yeya24/promlinter.(*visitor).Visit(0xc0188125c0, 0x17cb718, 0xc016a5a080, 0x1473e60, 0x14bc700)
	/xxx/go/pkg/mod/github.com/yeya24/[email protected]/promlinter.go:167 +0xde
go/ast.Walk(0x17c0720, 0xc0188125c0, 0x17cb718, 0xc016a5a080)
	/usr/lib/golang/src/go/ast/walk.go:52 +0x63
go/ast.walkExprList(0x17c0720, 0xc0188125c0, 0xc02bd11160, 0x1, 0x1)
	/usr/lib/golang/src/go/ast/walk.go:26 +0x9e
go/ast.Walk(0x17c0720, 0xc0188125c0, 0x17cb718, 0xc016a5a0c0)
	/usr/lib/golang/src/go/ast/walk.go:137 +0xfc5
go/ast.Walk(0x17c0720, 0xc0188125c0, 0x17cb970, 0xc02bd11180)
	/usr/lib/golang/src/go/ast/walk.go:196 +0x1a05
go/ast.walkStmtList(0x17c0720, 0xc0188125c0, 0xc02bd11220, 0x1, 0x1)
	/usr/lib/golang/src/go/ast/walk.go:32 +0x9e
go/ast.Walk(0x17c0720, 0xc0188125c0, 0x17cb6c8, 0xc00262b560)
	/usr/lib/golang/src/go/ast/walk.go:224 +0x1968
go/ast.Walk(0x17c0720, 0xc0188125c0, 0x17cbb50, 0xc016a5a100)
	/usr/lib/golang/src/go/ast/walk.go:231 +0x1af2
go/ast.walkStmtList(0x17c0720, 0xc0188125c0, 0xc016a5a200, 0x3, 0x4)
	/usr/lib/golang/src/go/ast/walk.go:32 +0x9e
go/ast.Walk(0x17c0720, 0xc0188125c0, 0x17cb7e0, 0xc016a5a240)
	/usr/lib/golang/src/go/ast/walk.go:260 +0x200e
go/ast.walkStmtList(0x17c0720, 0xc0188125c0, 0xc016a5a600, 0x3, 0x4)
	/usr/lib/golang/src/go/ast/walk.go:32 +0x9e
go/ast.Walk(0x17c0720, 0xc0188125c0, 0x17cb6c8, 0xc00262b6b0)
	/usr/lib/golang/src/go/ast/walk.go:224 +0x1968
go/ast.Walk(0x17c0720, 0xc0188125c0, 0x17cbd80, 0xc02bd11ab0)
	/usr/lib/golang/src/go/ast/walk.go:263 +0x1645
go/ast.walkStmtList(0x17c0720, 0xc0188125c0, 0xc02bd11ac0, 0x1, 0x1)
	/usr/lib/golang/src/go/ast/walk.go:32 +0x9e
go/ast.Walk(0x17c0720, 0xc0188125c0, 0x17cb6c8, 0xc00262b6e0)
	/usr/lib/golang/src/go/ast/walk.go:224 +0x1968
go/ast.Walk(0x17c0720, 0xc0188125c0, 0x17cba10, 0xc016a5a640)
	/usr/lib/golang/src/go/ast/walk.go:275 +0x6aa
go/ast.walkStmtList(0x17c0720, 0xc0188125c0, 0xc0022a6f80, 0x8, 0x8)
	/usr/lib/golang/src/go/ast/walk.go:32 +0x9e
go/ast.Walk(0x17c0720, 0xc0188125c0, 0x17cb6c8, 0xc00262b710)
	/usr/lib/golang/src/go/ast/walk.go:224 +0x1968
go/ast.Walk(0x17c0720, 0xc0188125c0, 0x17cba38, 0xc00262b740)
	/usr/lib/golang/src/go/ast/walk.go:344 +0xce6
go/ast.walkDeclList(0x17c0720, 0xc0188125c0, 0xc008bd0d00, 0x10, 0x10)
	/usr/lib/golang/src/go/ast/walk.go:38 +0x9e
go/ast.Walk(0x17c0720, 0xc0188125c0, 0x17cb9e8, 0xc0022a7780)
	/usr/lib/golang/src/go/ast/walk.go:353 +0x2446
github.com/yeya24/promlinter.RunLint(0xc002c9e280, 0xc00a51e220, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0xc02d7f0400, 0xc008c61ef0, ...)
	/xxx/go/pkg/mod/github.com/yeya24/[email protected]/promlinter.go:125 +0x145
github.com/golangci/golangci-lint/pkg/golinters.NewPromlinter.func1.1(0xc014324270, 0x1f8f3f5bd, 0x217ee00, 0xc0259a7e30, 0x2)
	/xxx/go/pkg/mod/github.com/golangci/[email protected]/pkg/golinters/promlinter.go:34 +0x9a
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyze(0xc003d888d0)
	/xxx/go/pkg/mod/github.com/golangci/[email protected]/pkg/golinters/goanalysis/runner_action.go:187 +0x9f2
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func2()
	/xxx/go/pkg/mod/github.com/golangci/[email protected]/pkg/golinters/goanalysis/runner_action.go:105 +0x2a
github.com/golangci/golangci-lint/pkg/timeutils.(*Stopwatch).TrackStage(0xc001e81770, 0x15ed094, 0xa, 0xc0046ea770)
	/xxx/go/pkg/mod/github.com/golangci/[email protected]/pkg/timeutils/stopwatch.go:111 +0x4d
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe(0xc003d888d0)
	/xxx/go/pkg/mod/github.com/golangci/[email protected]/pkg/golinters/goanalysis/runner_action.go:104 +0x91
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze.func2(0xc0182d8eb0, 0xc003d888d0)
	/xxx/go/pkg/mod/github.com/golangci/[email protected]/pkg/golinters/goanalysis/runner_loadingpackage.go:80 +0x65
created by github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze
	/xxx/go/pkg/mod/github.com/golangci/[email protected]/pkg/golinters/goanalysis/runner_loadingpackage.go:75 +0x316
WARN [runner] Can't run linter goanalysis_metalinter: goanalysis_metalinter: promlinter: package "main" (isInitialPkg: true, needAnalyzeSource: true): runtime error: index out of range [0] with length 0

Version of golangci-lint

golangci-lint has version v1.42.0 built from (unknown, mod sum: "h1:hqf1zo6zY3GKGjjBk3ttdH22tGwF6ZRpk6j6xyJmE8I=") on (unknown)

Configuration file

N/A

Go environment

go version go1.16.5 linux/amd64
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/xxx/.cache/go-build"
GOENV="/xxx/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/xxx/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/xxx/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/golang"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/golang/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.16.5"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/xxx/project/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 -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1300237905=/tmp/go-build -gno-record-gcc-switches"

Verbose output of running

> /xxx/go/bin/golangci-lint cache clean
> /xxx/go/bin/golangci-lint run -v
INFO [config_reader] Config search paths: [./ /xxx/project /xxx /xxx /]
INFO [config_reader] Used config file .golangci.yml
INFO [lintersdb] Active 11 linters: [deadcode gosimple govet ineffassign misspell staticcheck structcheck stylecheck typecheck unused varcheck]
INFO [loader] Go packages loading at mode 575 (deps|exports_file|name|types_sizes|compiled_files|files|imports) took 1.53225453s
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 398.701733ms
INFO [linters context/goanalysis] analyzers took 1m50.524254013s with top 10 stages: buildir: 1m11.617601594s, inspect: 2.968079386s, nilness: 2.499130096s, printf: 1.925284339s, ctrlflow: 1.739444823s, fact_purity: 1.631299152s, misspell: 1.627326038s, fact_deprecated: 1.623377977s, S1038: 1.433885735s, SA5012: 1.333104681s
INFO [runner] Issues before processing: 315, after processing: 0
INFO [runner] Processors filtering stat (out/in): identifier_marker: 313/313, nolint: 0/17, autogenerated_exclude: 313/315, path_prettifier: 315/315, skip_files: 315/315, cgo: 315/315, exclude: 313/313, exclude-rules: 17/313, filename_unadjuster: 315/315, skip_dirs: 315/315
INFO [runner] processing took 73.136263ms with stages: autogenerated_exclude: 29.98657ms, exclude-rules: 19.435927ms, nolint: 9.746214ms, identifier_marker: 8.502045ms, path_prettifier: 4.364939ms, skip_dirs: 1.015234ms, cgo: 49.66µs, filename_unadjuster: 28.787µs, max_same_issues: 1.952µs, uniq_by_line: 787ns, diff: 575ns, max_from_linter: 563ns, source_code: 558ns, path_shortener: 467ns, severity-rules: 445ns, max_per_file_from_linter: 360ns, sort_results: 351ns, skip_files: 319ns, exclude: 317ns, path_prefixer: 193ns
INFO [runner] linters took 11.582202297s with stages: goanalysis_metalinter: 11.508853034s
INFO File cache stats: 456 entries of total size 27.8MiB
INFO Memory: 137 samples, avg is 922.8MB, max is 1422.1MB
INFO Execution took 13.526862302s

Code example or link to a public repository

// add your code here
@rleungx rleungx added the bug Something isn't working label Sep 6, 2021
@boring-cyborg
Copy link

boring-cyborg bot commented Sep 6, 2021

Hey, thank you for opening your first Issue ! 🙂 If you would like to contribute we have a guide for contributors.

@ldez
Copy link
Member

ldez commented Sep 6, 2021

Hello @rleungx, could you provide a reproducible example?

Ping @yeya24

@ldez ldez added the feedback required Requires additional feedback label Sep 6, 2021
@rleungx
Copy link
Contributor Author

rleungx commented Sep 7, 2021

Try the following code with golangci-lint run --disable-all -E promlinter

package main

func main() {
	Counter()
}

func Counter() int {
	return 0
}

@SVilgelm
Copy link
Member

SVilgelm commented Sep 7, 2021

I can confirm same behavior with promlinter:

21-09-06 21:43 % ~/go/bin/promlinter lint main.go 
 
panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
github.com/yeya24/promlinter.(*visitor).parseCallerExpr(0x14000150e80, 0x14000150e00)
	/Users/sergeyvilgelm/go/pkg/mod/github.com/yeya24/[email protected]/promlinter.go:253 +0x8e8
github.com/yeya24/promlinter.(*visitor).Visit(0x14000150e80, {0x100dccfd0, 0x14000150e00})
	/Users/sergeyvilgelm/go/pkg/mod/github.com/yeya24/[email protected]/promlinter.go:167 +0xbc
go/ast.Walk({0x100dc7140, 0x14000150e80}, {0x100dccfd0, 0x14000150e00})
	/opt/homebrew/Cellar/go/1.17/libexec/src/go/ast/walk.go:50 +0x48
go/ast.Walk({0x100dc7140, 0x14000150e80}, {0x100dcd188, 0x1400011ba40})
	/opt/homebrew/Cellar/go/1.17/libexec/src/go/ast/walk.go:197 +0x1320
go/ast.walkStmtList({0x100dc7140, 0x14000150e80}, {0x1400011ba50, 0x1, 0x1})
	/opt/homebrew/Cellar/go/1.17/libexec/src/go/ast/walk.go:30 +0x9c
go/ast.Walk({0x100dc7140, 0x14000150e80}, {0x100dccf80, 0x140001dc990})
	/opt/homebrew/Cellar/go/1.17/libexec/src/go/ast/walk.go:225 +0x12a8
go/ast.Walk({0x100dc7140, 0x14000150e80}, {0x100dcd250, 0x140001dc9c0})
	/opt/homebrew/Cellar/go/1.17/libexec/src/go/ast/walk.go:346 +0x9e4
go/ast.walkDeclList({0x100dc7140, 0x14000150e80}, {0x14000152920, 0x2, 0x2})
	/opt/homebrew/Cellar/go/1.17/libexec/src/go/ast/walk.go:36 +0x9c
go/ast.Walk({0x100dc7140, 0x14000150e80}, {0x100dcd200, 0x140001ce400})
	/opt/homebrew/Cellar/go/1.17/libexec/src/go/ast/walk.go:355 +0x1b70
github.com/yeya24/promlinter.RunLint(0x14000150dc0, {0x14000138378, 0x1, 0x1}, {0x0, {0x0, 0x0, 0x0}})
	/Users/sergeyvilgelm/go/pkg/mod/github.com/yeya24/[email protected]/promlinter.go:125 +0x13c
main.main()
	/Users/sergeyvilgelm/go/pkg/mod/github.com/yeya24/[email protected]/cmd/promlinter/main.go:80 +0x10b4

@rleungx please report this issue in promlinter repo: https://github.com/yeya24/promlinter

@SVilgelm SVilgelm added blocked Need's direct action from maintainer dependencies Relates to an upstream dependency and removed feedback required Requires additional feedback labels Sep 7, 2021
@ldez ldez removed the blocked Need's direct action from maintainer label Sep 7, 2021
@butuzov
Copy link
Member

butuzov commented Sep 8, 2021

Looks like the issue is known (yeya24/promlinter#30) to the author

@AlekSi
Copy link
Contributor

AlekSi commented Oct 4, 2021

And that known issue is now resolved

@ldez
Copy link
Member

ldez commented Oct 4, 2021

@yeya24 could you create a release?

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.

5 participants