golangci / golangci-lint

Fast linters runner for Go
https://golangci-lint.run
GNU General Public License v3.0
14.91k stars 1.35k forks source link

Panic when using an analysis-based linter #934

Closed frioux closed 3 years ago

frioux commented 4 years ago

I understand that I am trying to get support on an as-of-yet unsubmitted PR for golangci-lint, but I'd appreciate some input if you can spare the time. I am able to run my linter with this simple main function. It works (albeit incredibly slowly) without any problems. When I try to run it with a single patch atop 1.22.2 built by go 1.13.4 I get the panic shown below. Any ideas?

Please include the following information:

Version of golangci-lint This version: https://github.com/ZipRecruiter/golangci-lint/commit/8ae68ec3592ec1e0366e915b781cae3cfbaa035f
Config file ```console $ cat .golangci.yml # Config file for golangci-lint, used by bin/gozr. # options for analysis running run: timeout: 5m tests: true build-tags: - lint skip-files: # Run "golangci-lint linters" for a list of available linters. Don't enable # any linters here, or they can't be disabled on the commandline. linters: disable-all: true enable: - bodyclose - deadcode - depguard - errcheck - gocritic - gofmt - goimports - golint - gosec - gosimple - govet - ineffassign - misspell - nakedret - pairs - prealloc - staticcheck - structcheck - typecheck - unconvert - varcheck fast: false # all available settings of specific linters linters-settings: pairs: pair-func: - .Log=0 - go.zr.org/common/go/log.Debug=3 - go.zr.org/common/go/log.Info=3 - go.zr.org/common/go/log.Log=3 - go.zr.org/common/go/log.InfoSampled=4 - go.zr.org/common/go/log.NewFromWriter=1 - go.zr.org/common/go/log.WithDetails=1 - go.zr.org/common/go/log.NewBuffer=0 - go.zr.org/common/go/errors.Wrap=2 - go.zr.org/common/go/errors/details.NewPairs=0 - go.zr.org/common/go/errors/details.Pairs.AddPairs=0 assume-pair: - go.zr.org/common/go/errors/details.Pairs depguard: list-type: blacklist include-go-root: true packages: - git.ziprecruiter.com/ZipRecruiter/ziprecruiter - git.zr.org/ZipRecruiter/ziprecruiter - github.com/kelseyhightower/envconfig - errors - github.com/pkg/errors - flag - github.com/alecthomas/kingpin - gopkg.in/alecthomas/kingpin.v1 - gopkg.in/alecthomas/kingpin.v2 - github.com/gin-gonic/gin - log - github.com/go-kit/kit/log - github.com/prometheus/common/log - go.uber.org/zap - go.uber.org/zap/zapcore - encoding/json - github.com/mailru/easyjson - github.com/segmentio/encoding/json - github.com/google/uuid - github.com/hashicorp/go-uuid - github.com/pborman/uuid - github.com/rogpeppe/fastuuid - github.com/satori/go.uuid - github.com/hashicorp/go-multierror - github.com/emersion/go-sasl - github.com/emersion/go-smtp - k8s.io/kubernetes - k8s.io/apimachinery/pkg/util - k8s.io/client-go/util - github.com/aws/aws-sdk-go/aws/session - github.com/aws/aws-sdk-go/aws/credentials/stscreds - github.com/aws/aws-sdk-go/service/sts - go.uber.org/goleak errcheck: check-blank: false ignore: fmt:.*,database/sql:Close,io:Close,net:Close,os:(Close|Remove(All)?|Setenv),go.zr.org/common/go/log:Log,go.zr.org/common/go/interfaces:Log,github.com/go-kit/kit/log:Log gocritic: enabled-tags: - diagnostic - experimental - opinionated - performance - style disabled-checks: - commentedOutCode - equalFold - exitAfterDefer - hugeParam - ifElseChain - octalLiteral - unnamedResult gofmt: simplify: true goimports: local-prefixes: go.zr.org golint: min-confidence: 0.0 govet: enable: - atomicalign - nilness - shadow - sortslice disable: - deepequalerrors nakedret: max-func-lines: 6 # output configuration options output: format: line-number print-issued-lines: false issues: exclude: - comment on exported type - should have( a package)? comment - declaration of .err. shadows declaration - .noCopy. is unused - G104. Errors unhandled - G107. Potential HTTP request made with variable url - G108. Profiling endpoint is automatically exposed on /debug/pprof - G204. Subprocess launching should be audited - G204. Subprocess launched with variable - G204. Subprocess launched with function call as argument or cmd arguments - G301. Expect directory permissions to be 0750 or less - G302. Expect file permissions to be 0600 or less - G304. Potential file inclusion via variable - G401. Use of weak cryptographic primitive - G505. Blacklisted import .crypto/sha1.. weak cryptographic primitive exclude-use-default: false max-issues-per-linter: 0 max-same-issues: 0 ```
Go environment ```console $ go version && go env go version go1.13.4 linux/amd64 GO111MODULE="on" GOARCH="amd64" GOBIN="" GOCACHE="/home/frew/.cache/go-build" GOENV="/home/frew/.config/go/env" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/home/frew/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org" GOROOT="/home/frew/sdk/go1.13.4" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/home/frew/sdk/go1.13.4/pkg/tool/linux_amd64" GCCGO="gccgo" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="/home/frew/code/zr0/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=/run/shm/go-build247774810=/tmp/go-build -gno-record-gcc-switches" ```
Verbose output of running ```console $ golangci-lint run -v INFO [config_reader] Config search paths: [./ /home/frew/code/zr0 /home/frew/code /home/frew /home /] INFO [config_reader] Used config file .golangci.yml INFO [lintersdb] Active 21 linters: [bodyclose deadcode depguard errcheck gocritic gofmt goimports golint gosec gosimple govet ineffassign misspell nakedret pairs prealloc staticcheck structcheck typecheck unconvert varcheck] INFO [lintersdb] Active 21 linters: [bodyclose deadcode depguard errcheck gocritic gofmt goimports golint gosec gosimple govet ineffassign misspell nakedret pairs prealloc staticcheck structcheck typecheck unconvert varcheck] INFO [loader] Go packages loading at mode 575 (types_sizes|compiled_files|deps|exports_file|imports|files|name) took 3.483172817s INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 245.986337ms INFO [runner/goanalysis_metalinter/goanalysis] analyzers took 0s with no stages INFO [runner/pairs/goanalysis] analyzers took 286.171565ms with top 10 stages: pairs: 286.171565ms WARN [linters context] Panic: pairs: package "httperrors" (isInitialPkg: true, needAnalyzeSource: true): runtime error: invalid memory address or nil pointer dereference: goroutine 14960 [running]: runtime/debug.Stack(0xfc6376, 0x3c, 0xc0017623b8) /home/frew/sdk/go1.13.4/src/runtime/debug/stack.go:24 +0x9d github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func1(0xc0015c22d0) /home/frew/code/golangci-lint/pkg/golinters/goanalysis/runner.go:485 +0x1b5 panic(0xdfed80, 0x17ccd70) /home/frew/sdk/go1.13.4/src/runtime/panic.go:679 +0x1b2 golang.org/x/tools/go/ast/astutil.Apply.func1(0xc0091b77d0, 0xc001763c80) /home/frew/code/golangci-lint/vendor/golang.org/x/tools/go/ast/astutil/rewrite.go:47 +0xa3 panic(0xdfed80, 0x17ccd70) /home/frew/sdk/go1.13.4/src/runtime/panic.go:679 +0x1b2 go/types.(*Package).Path(...) /home/frew/sdk/go1.13.4/src/go/types/package.go:30 github.com/ZipRecruiter/splinter/pairs.NewAnalyzer.func3.1(0xc009008eb0, 0x1114601) /home/frew/code/golangci-lint/vendor/github.com/ZipRecruiter/splinter/pairs/pairs.go:237 +0x222 golang.org/x/tools/go/ast/astutil.(*application).apply(0xc009008ea0, 0x11144e0, 0xc005cf3e80, 0xf16a67, 0x3, 0xc009008ee8, 0x11146e0, 0xc005cf3e40) /home/frew/code/golangci-lint/vendor/golang.org/x/tools/go/ast/astutil/rewrite.go:198 +0x3c18 golang.org/x/tools/go/ast/astutil.(*application).applyList(0xc009008ea0, 0x11144e0, 0xc005cf3e80, 0xf16a67, 0x3) /home/frew/code/golangci-lint/vendor/golang.org/x/tools/go/ast/astutil/rewrite.go:473 +0xa5 golang.org/x/tools/go/ast/astutil.(*application).apply(0xc009008ea0, 0x1114660, 0xc0059d3ad0, 0xf1737b, 0x4, 0xc009008ee8, 0x11144e0, 0xc005cf3e80) /home/frew/code/golangci-lint/vendor/golang.org/x/tools/go/ast/astutil/rewrite.go:330 +0xca9 golang.org/x/tools/go/ast/astutil.(*application).applyList(0xc009008ea0, 0x1114660, 0xc0059d3ad0, 0xf1737b, 0x4) /home/frew/code/golangci-lint/vendor/golang.org/x/tools/go/ast/astutil/rewrite.go:473 +0xa5 golang.org/x/tools/go/ast/astutil.(*application).apply(0xc009008ea0, 0x1114c60, 0xc005cf3ec0, 0xf170c7, 0x4, 0x0, 0x1114660, 0xc0059d3ad0) /home/frew/code/golangci-lint/vendor/golang.org/x/tools/go/ast/astutil/rewrite.go:345 +0x649 golang.org/x/tools/go/ast/astutil.(*application).apply(0xc009008ea0, 0x1114660, 0xc0059d3bf0, 0xf1737b, 0x4, 0xc009008ee8, 0x1114c60, 0xc005cf3ec0) /home/frew/code/golangci-lint/vendor/golang.org/x/tools/go/ast/astutil/rewrite.go:350 +0x893 golang.org/x/tools/go/ast/astutil.(*application).applyList(0xc009008ea0, 0x1114660, 0xc0059d3bf0, 0xf1737b, 0x4) /home/frew/code/golangci-lint/vendor/golang.org/x/tools/go/ast/astutil/rewrite.go:473 +0xa5 golang.org/x/tools/go/ast/astutil.(*application).apply(0xc009008ea0, 0x1114ae0, 0xc0059d3c20, 0xf170c7, 0x4, 0x0, 0x1114660, 0xc0059d3bf0) /home/frew/code/golangci-lint/vendor/golang.org/x/tools/go/ast/astutil/rewrite.go:345 +0x649 golang.org/x/tools/go/ast/astutil.(*application).apply(0xc009008ea0, 0x1114a60, 0xc0091ebb00, 0xf1824a, 0x5, 0xc009008ee8, 0x1114ae0, 0xc0059d3c20) /home/frew/code/golangci-lint/vendor/golang.org/x/tools/go/ast/astutil/rewrite.go:418 +0x249f golang.org/x/tools/go/ast/astutil.(*application).applyList(0xc009008ea0, 0x1114a60, 0xc0091ebb00, 0xf1824a, 0x5) /home/frew/code/golangci-lint/vendor/golang.org/x/tools/go/ast/astutil/rewrite.go:473 +0xa5 golang.org/x/tools/go/ast/astutil.(*application).apply(0xc009008ea0, 0x1115fe0, 0xc0091b77d0, 0xf17403, 0x4, 0x0, 0x1114a60, 0xc0091ebb00) /home/frew/code/golangci-lint/vendor/golang.org/x/tools/go/ast/astutil/rewrite.go:424 +0x13d7 golang.org/x/tools/go/ast/astutil.Apply(0x1114a60, 0xc0091ebb00, 0xc005d7d650, 0x0, 0x0, 0x0) /home/frew/code/golangci-lint/vendor/golang.org/x/tools/go/ast/astutil/rewrite.go:52 +0x14a github.com/ZipRecruiter/splinter/pairs.NewAnalyzer.func3(0xc0072c4dc0, 0x13a5885bd, 0x18d7560, 0xc00650d0d0, 0x2) /home/frew/code/golangci-lint/vendor/github.com/ZipRecruiter/splinter/pairs/pairs.go:195 +0x80 github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyze(0xc0015c22d0) /home/frew/code/golangci-lint/pkg/golinters/goanalysis/runner.go:567 +0xa94 github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func2() /home/frew/code/golangci-lint/pkg/golinters/goanalysis/runner.go:489 +0x2a github.com/golangci/golangci-lint/pkg/timeutils.(*Stopwatch).TrackStage(0xc0005b0000, 0xf194d8, 0x5, 0xc0017b0760) /home/frew/code/golangci-lint/pkg/timeutils/stopwatch.go:111 +0x50 github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe(0xc0015c22d0) /home/frew/code/golangci-lint/pkg/golinters/goanalysis/runner.go:488 +0x9e github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze.func3(0xc00984d650, 0xc0015c22d0) /home/frew/code/golangci-lint/pkg/golinters/goanalysis/runner.go:1033 +0x69 created by github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze /home/frew/code/golangci-lint/pkg/golinters/goanalysis/runner.go:1028 +0x31b INFO [runner] Issues before processing: 4859, after processing: 5 INFO [runner] Processors filtering stat (out/in): diff: 5/5, max_same_issues: 5/5, path_shortener: 5/5, path_prettifier: 4859/4859, skip_dirs: 4859/4859, max_per_file_from_linter: 5/5, skip_files: 4859/4859, nolint: 6/78, autogenerated_exclude: 3834/4859, identifier_marker: 3834/3834, exclude-rules: 78/78, max_from_li nter: 5/5, source_code: 5/5, cgo: 4859/4859, filename_unadjuster: 4859/4859, exclude: 78/3834, uniq_by_line: 5/6 INFO [runner] processing took 408.490543ms with stages: nolint: 190.169442ms, identifier_marker: 111.820257ms, exclude: 58.793568ms, path_prettifier: 24.252887ms, autogenerated_exclude: 12.552506ms, skip_dirs: 10.012645ms, cgo: 474.495µs, filename_unadjuster: 297.531µs, source_code: 103.42µs, uniq_by_line: 4.481µs, pa th_shortener: 2.885µs, max_per_file_from_linter: 2.452µs, max_same_issues: 1.709µs, skip_files: 672ns, max_from_linter: 559ns, diff: 524ns, exclude-rules: 510ns INFO [runner] linters took 3.061331632s with stages: pairs: 2.319965796s, goanalysis_metalinter: 332.744449ms job_services/mixer/public/mixer/mixer.go:226: File is not `gofmt`-ed with `-s` (gofmt) job_services/mixer/public/mixer/dmscore.go:29:70: exported method DMScore returns unexported type go.zr.org/job_services/mixer/public/mixer.dmScoreResponse, which can be annoying to use (golint) job_services/mixer/public/mixer/suggestjobs.go:13:2: struct field `PlacementId` should be `PlacementID` (golint) job_services/mixer/public/mixer/similarjobs.go:101:2: `isMagic5` is unused (structcheck) job_services/mixer/public/mixer/mixer.go:321:2: SA9003: empty branch (staticcheck) INFO File cache stats: 4 entries of total size 19.9KiB INFO Memory: 67 samples, avg is 211.4MB, max is 670.8MB INFO Execution took 6.799069951s ```
stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.