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

goanalysis_metalinter: SA9002: runtime error: index out of range [2] with length 1 #1730

Closed
3 tasks done
Juneezee opened this issue Feb 11, 2021 · 2 comments · Fixed by #1756
Closed
3 tasks done

goanalysis_metalinter: SA9002: runtime error: index out of range [2] with length 1 #1730

Juneezee opened this issue Feb 11, 2021 · 2 comments · Fixed by #1756
Labels
bug Something isn't working dependencies Relates to an upstream dependency

Comments

@Juneezee
Copy link

Juneezee commented Feb 11, 2021

Thank you for creating the issue!

  • 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).

Please include the following information:

Version of golangci-lint
$ golangci-lint --version
golangci-lint has version 1.36.0 built from 6c25d06 on 2021-01-26T13:14:05Z
Config file
$ cat .golangci.yml
cat: .golangci.yml: No such file or directory
Go environment
$ go version && go env
go version go1.15.8 linux/amd64
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/jun/.cache/go-build"
GOENV="/home/jun/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/jun/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/jun/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/jun/Desktop/log/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-build684445965=/tmp/go-build -gno-record-gcc-switches"
Verbose output of running
$ golangci-lint cache clean
$ golangci-lint run -v
INFO [config_reader] Config search paths: [./ /home/jun/Desktop/log /home/jun/Desktop /home/jun /home /] 
INFO [lintersdb] Active 10 linters: [deadcode errcheck gosimple govet ineffassign staticcheck structcheck typecheck unused varcheck] 
INFO [loader] Go packages loading at mode 575 (name|compiled_files|exports_file|files|imports|deps|types_sizes) took 169.662991ms 
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 18.217401ms 
INFO [linters context/goanalysis] analyzers took 2.471184931s with top 10 stages: buildir: 1.59844417s, fact_purity: 87.463008ms, inspect: 76.516578ms, ctrlflow: 75.431944ms, printf: 74.303308ms, fact_deprecated: 45.799404ms, ineffassign: 37.402104ms, S1038: 25.86167ms, S1019: 16.784328ms, bools: 16.056652ms 
WARN [linters context] Panic: SA9002: package "log" (isInitialPkg: true, needAnalyzeSource: true): runtime error: index out of range [2] with length 1: goroutine 826 [running]:
runtime/debug.Stack(0xf548ce, 0x3c, 0xc0037768d0)
	/opt/hostedtoolcache/go/1.15.6/x64/src/runtime/debug/stack.go:24 +0x9f
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func1(0xc001039ad0)
	/home/runner/work/golangci-lint/golangci-lint/pkg/golinters/goanalysis/runner.go:508 +0x1be
panic(0xe3fe80, 0xc0033fc5a0)
	/opt/hostedtoolcache/go/1.15.6/x64/src/runtime/panic.go:969 +0x1b9
honnef.co/go/tools/staticcheck.CheckNonOctalFileMode.func1(0x105e760, 0xc005b760c0)
	/home/runner/go/pkg/mod/honnef.co/go/tools@v0.0.1-2020.1.6/staticcheck/lint.go:2815 +0x77c
golang.org/x/tools/go/ast/inspector.(*Inspector).Preorder(0xc000cbc660, 0xc001045538, 0x1, 0x1, 0xc0010f7d48)
	/home/runner/go/pkg/mod/golang.org/x/tools@v0.0.0-20210105210202-9ed45478a130/go/ast/inspector/inspector.go:77 +0xa2
honnef.co/go/tools/code.Preorder(...)
	/home/runner/go/pkg/mod/honnef.co/go/tools@v0.0.1-2020.1.6/code/code.go:481
honnef.co/go/tools/staticcheck.CheckNonOctalFileMode(0xc005dd88f0, 0x95de16a0, 0x16b0b60, 0xc009672a78, 0x2)
	/home/runner/go/pkg/mod/honnef.co/go/tools@v0.0.1-2020.1.6/staticcheck/lint.go:2834 +0xcc
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyze(0xc001039ad0)
	/home/runner/work/golangci-lint/golangci-lint/pkg/golinters/goanalysis/runner.go:590 +0xa83
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func2()
	/home/runner/work/golangci-lint/golangci-lint/pkg/golinters/goanalysis/runner.go:512 +0x2a
github.com/golangci/golangci-lint/pkg/timeutils.(*Stopwatch).TrackStage(0xc0011d0140, 0xea714d, 0x6, 0xc001045770)
	/home/runner/work/golangci-lint/golangci-lint/pkg/timeutils/stopwatch.go:111 +0x50
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe(0xc001039ad0)
	/home/runner/work/golangci-lint/golangci-lint/pkg/golinters/goanalysis/runner.go:511 +0x91
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze.func2(0xc00b307960, 0xc001039ad0)
	/home/runner/work/golangci-lint/golangci-lint/pkg/golinters/goanalysis/runner.go:1059 +0x65
created by github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze
	/home/runner/work/golangci-lint/golangci-lint/pkg/golinters/goanalysis/runner.go:1054 +0x305 
WARN [runner] Can't run linter goanalysis_metalinter: goanalysis_metalinter: SA9002: package "log" (isInitialPkg: true, needAnalyzeSource: true): runtime error: index out of range [2] with length 1 
INFO [linters context/goanalysis] analyzers took 163.34508ms with top 10 stages: buildir: 101.323504ms, U1000: 62.021576ms 
INFO [runner] processing took 36.739µs with stages: max_same_issues: 2.934µs, autogenerated_exclude: 2.375µs, nolint: 2.374µs, exclude-rules: 1.956µs, skip_files: 1.956µs, severity-rules: 1.956µs, sort_results: 1.956µs, cgo: 1.886µs, path_prettifier: 1.886µs, max_per_file_from_linter: 1.886µs, path_prefixer: 1.886µs, filename_unadjuster: 1.886µs, path_shortener: 1.885µs, skip_dirs: 1.816µs, max_from_linter: 1.467µs, diff: 1.466µs, identifier_marker: 1.397µs, exclude: 1.397µs, source_code: 1.397µs, uniq_by_line: 977ns 
INFO [runner] linters took 2.537529046s with stages: goanalysis_metalinter: 2.318229714s, unused: 218.999923ms 
ERRO Running error: goanalysis_metalinter: SA9002: package "log" (isInitialPkg: true, needAnalyzeSource: true): runtime error: index out of range [2] with length 1 
INFO Memory: 29 samples, avg is 182.9MB, max is 275.7MB 
INFO Execution took 2.735348132s

I'm trying to add golangci-lint to the open-source Go project phuslu/log but the linter returns a runtime error.

The author of the project @phuslu was trying to run golangci-lint on GitHub Actions and the job failed as well, as shown by the job logs here.

@Juneezee Juneezee added the bug Something isn't working label Feb 11, 2021
@boring-cyborg
Copy link

boring-cyborg bot commented Feb 11, 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 Feb 11, 2021

Hello,

It's an issue with https://github.com/dominikh/go-tools, you can open an issue in the repo.

The issue is related to the rule SA9002

$ staticcheck --checks="SA9002" .
panic: runtime error: index out of range [2] with length 1

goroutine 360 [running]:
honnef.co/go/tools/staticcheck.CheckNonOctalFileMode.func1(0x9df540, 0xc0020e7180)
        /home/ldez/sources/go/src/honnef.co/go/tools/staticcheck/lint.go:2928 +0x7b5
golang.org/x/tools/go/ast/inspector.(*Inspector).Preorder(0xc000ba2500, 0xc000318dd8, 0x1, 0x1, 0xc000064de8)
        /home/ldez/sources/go/pkg/mod/golang.org/x/tools@v0.1.0/go/ast/inspector/inspector.go:77 +0xa2
honnef.co/go/tools/analysis/code.Preorder(...)
        /home/ldez/sources/go/src/honnef.co/go/tools/analysis/code/visit.go:16
honnef.co/go/tools/staticcheck.CheckNonOctalFileMode(0xc001658f70, 0x20996c8c, 0xc4b100, 0xc001658ee8, 0x0)
        /home/ldez/sources/go/src/honnef.co/go/tools/staticcheck/lint.go:2947 +0xcc
honnef.co/go/tools/lintcmd/runner.(*analyzerRunner).do(0xc001a7aa50, 0x9ea7e0, 0xc0004e5400, 0x0, 0x0)
        /home/ldez/sources/go/src/honnef.co/go/tools/lintcmd/runner/runner.go:938 +0x61e
honnef.co/go/tools/lintcmd/runner.genericHandle(0x9ea7e0, 0xc0004e5400, 0x9ea7e0, 0xc0004d8000, 0xc000c6b4a0, 0xc0002ca0b8, 0xc000d17120)
        /home/ldez/sources/go/src/honnef.co/go/tools/lintcmd/runner/runner.go:763 +0x18b
created by honnef.co/go/tools/lintcmd/runner.(*subrunner).runAnalyzers
        /home/ldez/sources/go/src/honnef.co/go/tools/lintcmd/runner/runner.go:1004 +0x5ca

As a workaround, you can do that:

diff --git i/file.go w/file.go
index fe01944..d147db4 100644
--- i/file.go
+++ w/file.go
@@ -152,7 +152,8 @@ func (w *FileWriter) Rotate() (err error) {
 
 func (w *FileWriter) rotate() (err error) {
        var file *os.File
-       file, err = os.OpenFile(w.fileargs(timeNow()))
+       args, flag, perm := w.fileargs(timeNow())
+       file, err = os.OpenFile(args, flag, perm)
        if err != nil {
                return err
        }
@@ -216,7 +217,8 @@ func (w *FileWriter) rotate() (err error) {
 }
 
 func (w *FileWriter) create() (err error) {
-       w.file, err = os.OpenFile(w.fileargs(timeNow()))
+       args, flag, perm := w.fileargs(timeNow())
+       w.file, err = os.OpenFile(args, flag, perm)
        if err != nil {
                return err
        }

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