Skip to content

Panic when running promlinter #2222

Closed
@rleungx

Description

@rleungx

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdependenciesRelates to an upstream dependency

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions