-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Using --fix
option results in panic: runtime error: index out of range [146] with length 146
#1726
Comments
Hey, thank you for opening your first Issue ! 🙂 If you would like to contribute we have a guide for contributors. |
I have now ignored the particular file using the package i18n
import (
"myproject/pkg/render"
"myproject/pkg/router"
"context"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"reflect"
"strings"
"github.com/ghodss/yaml"
"github.com/oleiade/reflections"
"myproject/pkg/render" // duplicated!
"myproject/pkg/router" // duplicated!
) Outputlevel=info msg="[config_reader] Config search paths: [./ /home/myuser/code/myproject /home/myuser/code /home/myuser /home /]"
level=info msg="[config_reader] Used config file .golangci.yml"
level=info msg="[lintersdb] Active 46 linters: [asciicheck bodyclose deadcode dogsled errcheck errorlint exportloopref funlen gci gochecknoinits gocognit gocritic gocyclo gofmt gofumpt goheader goimports golint gomodguard goprintffuncname gosec gosimple govet ineffassign interfacer lll makezero maligned misspell nakedret nestif noctx nolintlint predeclared rowserrcheck scopelint staticcheck structcheck stylecheck tparallel typecheck unconvert unparam unused varcheck whitespace]"
level=info msg="[loader] Go packages loading at mode 575 (name|compiled_files|deps|files|types_sizes|exports_file|imports) took 1.798327249s"
level=info msg="[runner/filename_unadjuster] Pre-built 0 adjustments in 40.214248ms"
level=info msg="[linters context/goanalysis] analyzers took 0s with no stages"
level=info msg="[linters context/goanalysis] analyzers took 0s with no stages"
level=info msg="[linters context/goanalysis] analyzers took 0s with no stages"
level=info msg="[runner] Issues before processing: 3626, after processing: 875"
level=info msg="[runner] Processors filtering stat (out/in): cgo: 3626/3626, filename_unadjuster: 3626/3626, path_prettifier: 3626/3626, skip_files: 3615/3626, autogenerated_exclude: 2208/3615, exclude: 2208/2208, exclude-rules: 1327/2208, nolint: 875/1327, max_from_linter: 875/875, source_code: 875/875, identifier_marker: 2208/2208, uniq_by_line: 875/875, diff: 875/875, max_same_issues: 875/875, severity-rules: 875/875, sort_results: 875/875, skip_dirs: 3615/3615, max_per_file_from_linter: 875/875, path_shortener: 875/875, path_prefixer: 875/875"
level=info msg="[runner] processing took 124.973306ms with stages: nolint: 54.200379ms, exclude-rules: 29.343616ms, identifier_marker: 26.240421ms, path_prettifier: 4.953255ms, source_code: 4.046131ms, autogenerated_exclude: 3.51567ms, skip_dirs: 824.895µs, max_same_issues: 647.328µs, skip_files: 334.042µs, max_per_file_from_linter: 293.83µs, cgo: 209.276µs, filename_unadjuster: 149.227µs, max_from_linter: 103.142µs, path_shortener: 77.328µs, uniq_by_line: 33.419µs, exclude: 401ns, diff: 321ns, sort_results: 252ns, severity-rules: 211ns, path_prefixer: 162ns"
level=info msg="[runner] linters took 195.010445ms with stages: goanalysis_metalinter: 67.996545ms, unused: 1.1468ms, makezero: 782.962µs"
level=info msg="Fix issue &result.Issue{FromLinter:\"gofumpt\", Text:\"File is not `gofumpt`-ed\", Severity:\"\", SourceLines:[]string{\"\\t\\\"context\\\"\", \"\"}, Replacement:(*result.Replacement)(0xc002438ae0), Pkg:(*packages.Package)(0xc000f88c60), LineRange:(*result.Range)(0xc0009a7930), Pos:token.Position{Filename:\"internal/pkg/indicator/service.go\", Offset:0, Line:4, Column:0}, HunkPos:0, ExpectNoLint:false, ExpectedNoLintLinter:\"\"} with range {4 5}"
level=info msg="Skip issue &result.Issue{FromLinter:\"gci\", Text:\"File is not `gci`-ed with -local myproject\", Severity:\"\", SourceLines:[]string{\"\"}, Replacement:(*result.Replacement)(0xc002438930), Pkg:(*packages.Package)(0xc000f88c60), LineRange:(*result.Range)(nil), Pos:token.Position{Filename:\"internal/pkg/indicator/service.go\", Offset:0, Line:5, Column:0}, HunkPos:0, ExpectNoLint:false, ExpectedNoLintLinter:\"\"}: intersects with end 5"
level=info msg="Fix issue &result.Issue{FromLinter:\"gofumpt\", Text:\"File is not `gofumpt`-ed\", Severity:\"\", SourceLines:[]string{\"\\t\\\"myproject/pkg/db\\\"\"}, Replacement:(*result.Replacement)(0xc002438b10), Pkg:(*packages.Package)(0xc000f88c60), LineRange:(*result.Range)(nil), Pos:token.Position{Filename:\"internal/pkg/indicator/service.go\", Offset:0, Line:8, Column:0}, HunkPos:0, ExpectNoLint:false, ExpectedNoLintLinter:\"\"} with range {8 8}"
level=info msg="Fix issue &result.Issue{FromLinter:\"gci\", Text:\"File is not `gci`-ed with -local myproject\", Severity:\"\", SourceLines:[]string{\"\", \"\\t\\\"github.com/pkg/errors\\\"\"}, Replacement:(*result.Replacement)(0xc002438990), Pkg:(*packages.Package)(0xc000f88c60), LineRange:(*result.Range)(0xc0009a7880), Pos:token.Position{Filename:\"internal/pkg/indicator/service.go\", Offset:0, Line:9, Column:0}, HunkPos:0, ExpectNoLint:false, ExpectedNoLintLinter:\"\"} with range {9 10}"
// *snip* because the output is too long for GitHub...
level=info msg="Fix issue &result.Issue{FromLinter:\"gci\", Text:\"File is not `gci`-ed with -local myproject\", Severity:\"\", SourceLines:[]string{\"\\t\\\"github.com/stretchr/testify/require\\\"\"}, Replacement:(*result.Replacement)(0xc0002836e0), Pkg:(*packages.Package)(0xc000e910e0), LineRange:(*result.Range)(nil), Pos:token.Position{Filename:\"internal/gets/displaygroup_test.go\", Offset:0, Line:14, Column:0}, HunkPos:0, ExpectNoLint:false, ExpectedNoLintLinter:\"\"} with range {14 14}"
level=info msg="Fix issue &result.Issue{FromLinter:\"gofumpt\", Text:\"File is not `gofumpt`-ed\", Severity:\"\", SourceLines:[]string{\"\\t\\\"context\\\"\", \"\\t\\\"testing\\\"\", \"\\t\\\"time\\\"\", \"\"}, Replacement:(*result.Replacement)(0xc0039ffaa0), Pkg:(*packages.Package)(0xc000f24c60), LineRange:(*result.Range)(0xc00083e5b0), Pos:token.Position{Filename:\"internal/pkg/checkpoint/service_test.go\", Offset:0, Line:4, Column:0}, HunkPos:0, ExpectNoLint:false, ExpectedNoLintLinter:\"\"} with range {4 7}"
level=info msg="Skip issue &result.Issue{FromLinter:\"gci\", Text:\"File is not `gci`-ed with -local myproject\", Severity:\"\", SourceLines:[]string{\"\\t\\\"time\\\"\"}, Replacement:(*result.Replacement)(0xc0039ff8f0), Pkg:(*packages.Package)(0xc000f24c60), LineRange:(*result.Range)(nil), Pos:token.Position{Filename:\"internal/pkg/checkpoint/service_test.go\", Offset:0, Line:6, Column:0}, HunkPos:0, ExpectNoLint:false, ExpectedNoLintLinter:\"\"}: intersects with end 7"
level=info msg="Fix issue &result.Issue{FromLinter:\"gofumpt\", Text:\"File is not `gofumpt`-ed\", Severity:\"\", SourceLines:[]string{\"\\t\\\"myproject/pkg/log\\\"\"}, Replacement:(*result.Replacement)(0xc0039ffad0), Pkg:(*packages.Package)(0xc000f24c60), LineRange:(*result.Range)(nil), Pos:token.Position{Filename:\"internal/pkg/checkpoint/service_test.go\", Offset:0, Line:14, Column:0}, HunkPos:0, ExpectNoLint:false, ExpectedNoLintLinter:\"\"} with range {14 14}"
level=info msg="Fix issue &result.Issue{FromLinter:\"gci\", Text:\"File is not `gci`-ed with -local myproject\", Severity:\"\", SourceLines:[]string{\"\", \"\\t\\\"github.com/DATA-DOG/go-sqlmock\\\"\", \"\\t\\\"github.com/stretchr/testify/require\\\"\"}, Replacement:(*result.Replacement)(0xc0039ff920), Pkg:(*packages.Package)(0xc000f24c60), LineRange:(*result.Range)(0xc00083e4d0), Pos:token.Position{Filename:\"internal/pkg/checkpoint/service_test.go\", Offset:0, Line:15, Column:0}, HunkPos:0, ExpectNoLint:false, ExpectedNoLintLinter:\"\"} with range {15 17}"
level=info msg="fixer took 169.506662ms with stages: all: 169.506662ms"
level=info msg="File cache stats: 227 entries of total size 1000.7KiB"
level=info msg="Memory: 24 samples, avg is 85.6MB, max is 139.1MB"
level=info msg="Execution took 2.208759995s"
|
Duplicate of #1490 |
Your second comment is a duplicate of #1490. But your initial issue seems different. |
Thank you @ldez, disabling Regarding the other issue: I don't have the problem anymore today, but reverting the git repo back to a few days ago, the problem is reproducible. The only thing that was changed in the file since then was an added newline at the end (without the newline it panics): -}
+}
\ No newline at end of file I can now reproduce the issue with any file, by removing the last newline from it: // main.go
package main
import "fmt"
func main() {
fmt.Println("Hello World")
} $ golangci-lint run --fix
# all good
# remove last byte
$ truncate -s -1 main.go
# obviously still valid code
$ go run main.go
Hello World
# panics!
$ golangci-lint run --fix
panic: runtime error: index out of range [7] with length 7
goroutine 1 [running]:
github.com/golangci/golangci-lint/pkg/result/processors.Fixer.mergeLineIssues(0xc000686e00, 0x107e0e0, 0xc00069c5a0, 0xc00078b5c0, 0xc00189c7d0, 0x8, 0xc00017adc0, 0x2, 0x2, 0xc0000cda20, ...)
... |
I tried to reproduce with your example, but I cannot: $ golangci-lint version
golangci-lint has version 1.36.0 built from 6c25d06 on 2021-01-26T13:14:05Z
$ truncate -s -1 main.go
$ golangci-lint run
main.go:7: File is not `gofmt`-ed with `-s` (gofmt)
}
$ go run main.go
Hello World
$ golangci-lint run --fix
$ golangci-lint run
main.go:7: File is not `gofmt`-ed with `-s` (gofmt)
} the fix is never applied but I don't get a panic. |
That's strange! I am still abe to reproduce the issue. $ golangci-lint version
golangci-lint has version 1.36.0 built from 6c25d06 on 2021-01-26T13:14:05Z package main
import (
"fmt"
)
func main() {
fmt.Println("Hello World")
}
# .golangci.yml
linters:
enable-all: true
Here's a download link to the original file I have used: |
I tried with your configuration and your file: $ hexdump -C main.go
00000000 70 61 63 6b 61 67 65 20 6d 61 69 6e 0a 0a 69 6d |package main..im|
00000010 70 6f 72 74 20 28 0a 09 22 66 6d 74 22 0a 29 0a |port (.."fmt".).|
00000020 0a 66 75 6e 63 20 6d 61 69 6e 28 29 20 7b 0a 09 |.func main() {..|
00000030 66 6d 74 2e 50 72 69 6e 74 6c 6e 28 22 48 65 6c |fmt.Println("Hel|
00000040 6c 6f 20 57 6f 72 6c 64 22 29 0a 7d |lo World").}| in a clean project and I still not reproduce 🤔 |
Huh! What Go version are you running?
I am running Ubuntu 20.04, but I cannot imagine that the OS could be the culprit. Edit: If I find the time I'll try and debug the code locally, as I am able to reproduce this. |
The local version of Go doesn't have any importance, I use the binary from the download page. |
Could you try to clean your cache |
Cleaning the cache does not help. I did look into this and the problem seems to be that the generated patch (like the golangci-lint/pkg/golinters/gofmt_common.go Line 269 in 42ff682
But the file itself only has 9 lines because of the missing new line at the end. So there is not 10th line to fix. This problem is actually detected here (a warning is printed):
But the Issue is still processed, as it is returned from the closure despite the error. Changing this to a
Once this gets to the golangci-lint/pkg/result/processors/fixer.go Line 121 in c1d7cfd
I was able to reproduce this on two (Ubuntu) systems with any Go file (using the |
I tested on 3 computers:
And I still not reproduce 🤔 |
😁 what a strange problem! What's the length of your I did reproduce it like this: In the root of your repo, I created a package main
import (
"fmt"
)
func main() {
fmt.Println("Hello World")
} This is 10 lines long (including the new line at the end). I truncated the last byte, so it only has 9 lines now: truncate -s -1 crash.go Running everything as is from your repo (no additional config), the go run cmd/golangci-lint/main.go run --fix |
could you run:
FYI |
File with new line$ go run cmd/golangci-lint/main.go run --fix -v
INFO [config_reader] Config search paths: [./ /home/offline/Code/golangci-lint /home/offline/Code /home/offline /home /]
INFO [config_reader] Used config file .golangci.yml
INFO [lintersdb] Active 38 linters: [bodyclose deadcode depguard dogsled dupl errcheck exhaustive funlen gochecknoinits goconst gocritic gocyclo gofmt goimports golint gomnd goprintffuncname gosec gosimple govet ineffassign interfacer lll misspell nakedret noctx nolintlint rowserrcheck scopelint staticcheck structcheck stylecheck typecheck unconvert unparam unused varcheck whitespace]
INFO [loader] Go packages loading at mode 575 (types_sizes|files|imports|name|compiled_files|deps|exports_file) took 550.811469ms
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 20.025155ms
INFO [linters context/goanalysis] analyzers took 58.107126918s with top 10 stages: buildir: 31.105111975s, buildssa: 3.747009081s, dupl: 2.398601938s, gocritic: 1.645466988s, exhaustive: 1.609474469s, unconvert: 1.575949741s, goimports: 1.521783495s, inspect: 1.275985839s, interfacer: 877.95695ms, fact_purity: 827.615221ms
INFO [linters context/goanalysis] analyzers took 2.535382411s with top 10 stages: buildir: 2.026869101s, U1000: 508.51331ms
INFO [runner/skip dirs] Skipped 5 issues from dir test/testdata_etc/abspath by pattern test/testdata_etc
INFO [runner/skip dirs] Skipped 15 issues from dir internal/renameio by pattern internal/renameio
INFO [runner/skip dirs] Skipped 77 issues from dir internal/cache by pattern internal/cache
INFO [runner/skip dirs] Skipped 3 issues from dir test/testdata_etc/unused_exported by pattern test/testdata_etc
INFO [runner/skip dirs] Skipped 3 issues from dir test/testdata_etc/unused_exported/lib by pattern test/testdata_etc
INFO [runner/skip dirs] Skipped 2 issues from dir internal/robustio by pattern internal/robustio
INFO [runner] Issues before processing: 1048, after processing: 0
INFO [runner] Processors filtering stat (out/in): identifier_marker: 943/943, exclude: 943/943, exclude-rules: 111/943, filename_unadjuster: 1048/1048, path_prettifier: 1048/1048, autogenerated_exclude: 943/943, cgo: 1048/1048, skip_files: 1048/1048, skip_dirs: 943/1048, nolint: 0/111
INFO [runner] processing took 75.959915ms with stages: exclude-rules: 24.264635ms, nolint: 23.125218ms, identifier_marker: 21.492663ms, path_prettifier: 3.326031ms, autogenerated_exclude: 2.873107ms, skip_dirs: 706.01µs, cgo: 107.433µs, filename_unadjuster: 58.86µs, max_same_issues: 1.19µs, uniq_by_line: 999ns, source_code: 582ns, skip_files: 458ns, exclude: 449ns, max_from_linter: 440ns, diff: 422ns, max_per_file_from_linter: 408ns, path_shortener: 364ns, severity-rules: 263ns, sort_results: 220ns, path_prefixer: 163ns
INFO [runner] linters took 15.153146772s with stages: goanalysis_metalinter: 13.550474932s, unused: 1.526604304s
INFO fixer took 0s with no stages
INFO File cache stats: 202 entries of total size 549.0KiB
INFO Memory: 155 samples, avg is 406.4MB, max is 612.5MB
INFO Execution took 15.729806276s Without new line$ go run cmd/golangci-lint/main.go run --fix -v
INFO [config_reader] Config search paths: [./ /home/offline/Code/golangci-lint /home/offline/Code /home/offline /home /]
INFO [config_reader] Used config file .golangci.yml
INFO [lintersdb] Active 38 linters: [bodyclose deadcode depguard dogsled dupl errcheck exhaustive funlen gochecknoinits goconst gocritic gocyclo gofmt goimports golint gomnd goprintffuncname gosec gosimple govet ineffassign interfacer lll misspell nakedret noctx nolintlint rowserrcheck scopelint staticcheck structcheck stylecheck typecheck unconvert unparam unused varcheck whitespace]
INFO [loader] Go packages loading at mode 575 (deps|exports_file|files|imports|types_sizes|compiled_files|name) took 655.636955ms
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 26.529292ms
INFO [linters context/goanalysis] analyzers took 23.686826ms with top 10 stages: buildir: 4.813634ms, gofmt: 4.381784ms, buildssa: 4.107576ms, goimports: 2.800601ms, unconvert: 1.831023ms, interfacer: 1.622957ms, gocritic: 460.239µs, unparam: 361.545µs, depguard: 229.913µs, fact_deprecated: 227.905µs
INFO [linters context/goanalysis] analyzers took 3.111447ms with top 10 stages: buildir: 2.993732ms, U1000: 117.715µs
WARN [runner/source_code] Failed to get line 10 for file crash.go: invalid file line index0 (9) >= len(fc) (9)
WARN [runner/source_code] Failed to get line 10 for file crash.go: invalid file line index0 (9) >= len(fc) (9)
INFO [runner/skip dirs] Skipped 3 issues from dir test/testdata_etc/unused_exported/lib by pattern test/testdata_etc
INFO [runner/skip dirs] Skipped 5 issues from dir test/testdata_etc/abspath by pattern test/testdata_etc
INFO [runner/skip dirs] Skipped 3 issues from dir test/testdata_etc/unused_exported by pattern test/testdata_etc
INFO [runner/skip dirs] Skipped 2 issues from dir internal/robustio by pattern internal/robustio
INFO [runner/skip dirs] Skipped 15 issues from dir internal/renameio by pattern internal/renameio
INFO [runner/skip dirs] Skipped 77 issues from dir internal/cache by pattern internal/cache
INFO [runner] Issues before processing: 1052, after processing: 4
INFO [runner] Processors filtering stat (out/in): filename_unadjuster: 1052/1052, autogenerated_exclude: 947/947, identifier_marker: 947/947, exclude: 947/947, path_shortener: 4/4, cgo: 1052/1052, uniq_by_line: 4/4, max_per_file_from_linter: 4/4, max_from_linter: 4/4, path_prefixer: 4/4, sort_results: 4/4, path_prettifier: 1052/1052, skip_files: 1052/1052, exclude-rules: 115/947, nolint: 4/115, diff: 4/4, source_code: 4/4, skip_dirs: 947/1052, max_same_issues: 4/4, severity-rules: 4/4
INFO [runner] processing took 65.042328ms with stages: identifier_marker: 22.211579ms, exclude-rules: 17.646574ms, nolint: 17.316716ms, path_prettifier: 4.137834ms, autogenerated_exclude: 2.87314ms, skip_dirs: 586.408µs, cgo: 106.7µs, source_code: 79.299µs, filename_unadjuster: 72.853µs, path_shortener: 2.716µs, max_same_issues: 2.071µs, uniq_by_line: 1.918µs, max_per_file_from_linter: 1.295µs, max_from_linter: 802ns, diff: 589ns, exclude: 520ns, skip_files: 440ns, sort_results: 307ns, severity-rules: 295ns, path_prefixer: 272ns
INFO [runner] linters took 411.821626ms with stages: goanalysis_metalinter: 293.45955ms, unused: 53.208256ms
INFO Line 9 has multiple issues but at least one of them isn't inline: []result.Issue{result.Issue{FromLinter:"gofmt", Text:"File is not `gofmt`-ed with `-s`", Severity:"", SourceLines:[]string{"}"}, Replacement:(*result.Replacement)(0xc000b73090), Pkg:(*packages.Package)(0xc0008eed80), LineRange:(*result.Range)(nil), Pos:token.Position{Filename:"crash.go", Offset:0, Line:9, Column:0}, HunkPos:0, ExpectNoLint:false, ExpectedNoLintLinter:""}, result.Issue{FromLinter:"goimports", Text:"File is not `goimports`-ed with -local github.com/golangci/golangci-lint", Severity:"", SourceLines:[]string{"}"}, Replacement:(*result.Replacement)(0xc000b72f90), Pkg:(*packages.Package)(0xc0008eed80), LineRange:(*result.Range)(nil), Pos:token.Position{Filename:"crash.go", Offset:0, Line:9, Column:0}, HunkPos:0, ExpectNoLint:false, ExpectedNoLintLinter:""}}
INFO Memory: 13 samples, avg is 97.1MB, max is 138.6MB
INFO Execution took 1.101194843s
panic: runtime error: index out of range [9] with length 9
goroutine 1 [running]:
github.com/golangci/golangci-lint/pkg/result/processors.Fixer.mergeLineIssues(0xc00065c000, 0x14b9b20, 0xc000629320, 0xc000796840, 0xc000fce910, 0xa, 0xc002144580, 0x2, 0x2, 0xc00022a2a0, ...)
/home/offline/Code/golangci-lint/pkg/result/processors/fixer.go:121 +0x599
github.com/golangci/golangci-lint/pkg/result/processors.Fixer.fixIssuesInFile(0xc00065c000, 0x14b9b20, 0xc000629320, 0xc000796840, 0xc000fce910, 0xc000b90f21, 0x8, 0xc0002a38c0, 0x1, 0x4, ...)
/home/offline/Code/golangci-lint/pkg/result/processors/fixer.go:98 +0x625
github.com/golangci/golangci-lint/pkg/result/processors.Fixer.Process.func1()
/home/offline/Code/golangci-lint/pkg/result/processors/fixer.go:60 +0xae
github.com/golangci/golangci-lint/pkg/timeutils.(*Stopwatch).TrackStage(0xc000fce910, 0x12cafcb, 0x3, 0xc0004cb6a0)
/home/offline/Code/golangci-lint/pkg/timeutils/stopwatch.go:111 +0x50
github.com/golangci/golangci-lint/pkg/result/processors.Fixer.Process(0xc00065c000, 0x14b9b20, 0xc000629320, 0xc000796840, 0xc000fce910, 0xc0002a3340, 0x4, 0x4, 0x2, 0x2, ...)
/home/offline/Code/golangci-lint/pkg/result/processors/fixer.go:59 +0x665
github.com/golangci/golangci-lint/pkg/commands.(*Executor).runAnalysis(0xc000126800, 0x14af6e0, 0xc0007b2780, 0xc0007fcf00, 0x0, 0x2, 0xc0007b2780, 0x14af6a0, 0xc0001ac010, 0x0, ...)
/home/offline/Code/golangci-lint/pkg/commands/run.go:352 +0x6f7
github.com/golangci/golangci-lint/pkg/commands.(*Executor).runAndPrint(0xc000126800, 0x14af6e0, 0xc0007b2780, 0xc0007fcf00, 0x0, 0x2, 0x0, 0x0)
/home/offline/Code/golangci-lint/pkg/commands/run.go:387 +0x12f
github.com/golangci/golangci-lint/pkg/commands.(*Executor).executeRun(0xc000126800, 0xc000216c80, 0xc0007fcf00, 0x0, 0x2)
/home/offline/Code/golangci-lint/pkg/commands/run.go:452 +0x177
github.com/spf13/cobra.(*Command).execute(0xc000216c80, 0xc0007fcee0, 0x2, 0x2, 0xc000216c80, 0xc0007fcee0)
/home/offline/Code/go/pkg/mod/github.com/spf13/[email protected]/command.go:856 +0x2c2
github.com/spf13/cobra.(*Command).ExecuteC(0xc000216a00, 0x6, 0x12ca701, 0x1)
/home/offline/Code/go/pkg/mod/github.com/spf13/[email protected]/command.go:960 +0x375
github.com/spf13/cobra.(*Command).Execute(...)
/home/offline/Code/go/pkg/mod/github.com/spf13/[email protected]/command.go:897
github.com/golangci/golangci-lint/pkg/commands.(*Executor).Execute(...)
/home/offline/Code/golangci-lint/pkg/commands/executor.go:147
main.main()
/home/offline/Code/golangci-lint/cmd/golangci-lint/main.go:21 +0x7e
exit status 2
Here's the context right before the panic: I do get the same Replacement Data: |
$ go run ./cmd/golangci-lint/ run --fix -v
INFO [config_reader] Config search paths: [./ /home/ldez/sources/go/src/github.com/golangci/golangci-lint /home/ldez/sources/go/src/github.com/golangci /home/ldez/sources/go/src/github.com /home/ldez/sources/go/src /home/ldez/sources/go /home/ldez/sources /home/ldez /home /]
INFO [config_reader] Used config file .golangci.yml
INFO [lintersdb] Active 37 linters: [bodyclose deadcode depguard dogsled dupl errcheck exhaustive funlen gochecknoinits goconst gocritic gocyclo gofmt goimports golint gomnd goprintffuncname gosec gosimple govet ineffassign lll misspell nakedret noctx nolintlint rowserrcheck scopelint staticcheck structcheck stylecheck typecheck unconvert unparam unused varcheck whitespace]
INFO [loader] Go packages loading at mode 575 (exports_file|files|types_sizes|compiled_files|deps|imports|name) took 685.636431ms
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 17.09254ms
INFO [linters context/goanalysis] analyzers took 52.645459013s with top 10 stages: buildir: 23.928657136s, buildssa: 2.340841823s, exhaustive: 2.099818129s, inspect: 1.561163007s, dupl: 1.384390564s, unconvert: 1.065587477s, gocritic: 962.127068ms, fact_deprecated: 941.086536ms, goimports: 907.903399ms, gosec: 852.809959ms
INFO [linters context/goanalysis] analyzers took 997.454223ms with top 10 stages: buildir: 787.149629ms, unused: 128.511421ms, directives: 60.356653ms, isgenerated: 21.43652ms
INFO [runner/skip dirs] Skipped 5 issues from dir test/testdata_etc/abspath by pattern test/testdata_etc
INFO [runner/skip dirs] Skipped 15 issues from dir internal/renameio by pattern internal/renameio
INFO [runner/skip dirs] Skipped 77 issues from dir internal/cache by pattern internal/cache
INFO [runner/skip dirs] Skipped 3 issues from dir test/testdata_etc/unused_exported by pattern test/testdata_etc
INFO [runner/skip dirs] Skipped 2 issues from dir internal/robustio by pattern internal/robustio
INFO [runner/skip dirs] Skipped 3 issues from dir test/testdata_etc/unused_exported/lib by pattern test/testdata_etc
INFO [runner] Issues before processing: 1054, after processing: 2
INFO [runner] Processors filtering stat (out/in): source_code: 2/2, path_prefixer: 2/2, exclude: 949/949, exclude-rules: 111/949, diff: 2/2, max_per_file_from_linter: 2/2, path_shortener: 2/2, skip_files: 1054/1054, skip_dirs: 949/1054, identifier_marker: 949/949, max_same_issues: 2/2, cgo: 1054/1054, autogenerated_exclude: 949/949, sort_results: 2/2, max_from_linter: 2/2, severity-rules: 2/2, filename_unadjuster: 1054/1054, path_prettifier: 1054/1054, nolint: 2/111, uniq_by_line: 2/2
INFO [runner] processing took 60.4996ms with stages: identifier_marker: 22.203471ms, exclude-rules: 18.49865ms, nolint: 13.119788ms, path_prettifier: 4.311373ms, autogenerated_exclude: 1.714233ms, skip_dirs: 470.572µs, cgo: 102.96µs, filename_unadjuster: 53.723µs, source_code: 18.086µs, path_shortener: 1.579µs, uniq_by_line: 1.151µs, max_same_issues: 1.068µs, max_per_file_from_linter: 853ns, max_from_linter: 557ns, skip_files: 341ns, exclude: 318ns, diff: 279ns, sort_results: 249ns, severity-rules: 224ns, path_prefixer: 125ns
INFO [runner] linters took 7.273060461s with stages: goanalysis_metalinter: 6.729794234s, unused: 482.688142ms
origFileLines 9 lineNum 9
INFO Line 9 has multiple issues but at least one of them isn't inline: []result.Issue{result.Issue{FromLinter:"gofmt", Text:"File is not `gofmt`-ed with `-s`", Severity:"", SourceLines:[]string{"}"}, Replacement:(*result.Replacement)(0xc0099df310), Pkg:(*packages.Package)(0xc000aaab40), LineRange:(*result.Range)(nil), Pos:token.Position{Filename:"crash.go", Offset:0, Line:9, Column:0}, HunkPos:0, ExpectNoLint:false, ExpectedNoLintLinter:""}, result.Issue{FromLinter:"goimports", Text:"File is not `goimports`-ed with -local github.com/golangci/golangci-lint", Severity:"", SourceLines:[]string{"}"}, Replacement:(*result.Replacement)(0xc003eee150), Pkg:(*packages.Package)(0xc000aaab40), LineRange:(*result.Range)(nil), Pos:token.Position{Filename:"crash.go", Offset:0, Line:9, Column:0}, HunkPos:0, ExpectNoLint:false, ExpectedNoLintLinter:""}}
INFO Fix issue &result.Issue{FromLinter:"gofmt", Text:"File is not `gofmt`-ed with `-s`", Severity:"", SourceLines:[]string{"}"}, Replacement:(*result.Replacement)(0xc0099df310), Pkg:(*packages.Package)(0xc000aaab40), LineRange:(*result.Range)(nil), Pos:token.Position{Filename:"crash.go", Offset:0, Line:9, Column:0}, HunkPos:0, ExpectNoLint:false, ExpectedNoLintLinter:""} with range {9 9}
INFO fixer took 214.138µs with stages: all: 214.138µs
INFO File cache stats: 204 entries of total size 549.6KiB
INFO Memory: 81 samples, avg is 444.1MB, max is 680.0MB
INFO Execution took 7.982446388s |
Could you update your local binary of goimports? |
@tobias-kuendig any news? |
Sorry, I was a few days away from work. While writing you a lengthy response with all kind of debug information, I think I found the culprit: I have german diff outputs ( As a quick check, I have replaced their diff testdata with german versions and most of their tests are failing now. It seems the package is not language aware. |
Hello, I have the same issue. |
It usually is because a file does not have a empty line at the end of the file. Just add the empty line and run the linter again. |
OK, I finally understood that after several attempts. Thank you ! |
It always crashes when processing the same file. The file is valid Go code and does not contain anything special.
Version of golangci-lint
Config file
Go environment
Verbose output of running
The text was updated successfully, but these errors were encountered: