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

panic out of range when diagnostic is on final line #5285

Closed
6 of 7 tasks
rbrady98 opened this issue Jan 2, 2025 · 1 comment · Fixed by #5287
Closed
6 of 7 tasks

panic out of range when diagnostic is on final line #5285

rbrady98 opened this issue Jan 2, 2025 · 1 comment · Fixed by #5287
Assignees
Labels
bug Something isn't working

Comments

@rbrady98
Copy link

rbrady98 commented Jan 2, 2025

Welcome

  • Yes, I'm using a binary release within 2 latest releases. Only such installations are supported.
  • Yes, I've searched similar issues on GitHub and didn't find any.
  • Yes, I've read the typecheck section of the FAQ.
  • Yes, I've tried with the standalone linter if available (e.g., gocritic, go vet, etc.).
  • I agree to follow this project's Code of Conduct

Description of the problem

golangci-lint run panics when trying to generate diagnostic message for final line of file. The code which generates the line number seems to go out of bounds.

The example below shows a 10 line example, if instead we add another blank line at the end making it 11 lines I don't get a panic and get the output:

main.go:11:1: File is not properly formatted (gofumpt)

^

Where you can see it generates the output for line 11 which now exists in the file.

Version of golangci-lint

$ golangci-lint --version
# golangci-lint has version 1.63.2 built with go1.23.4 from 15412b30 on 2025-01-02T12:43:20

Configuration

linters:
  disable-all: true
  enable:
    - gofumpt

Go environment

$ go version && go env
go version go1.23.4 darwin/arm64
GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/bian/Library/Caches/go-build'
GOENV='/Users/bian/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/bian/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/bian/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/homebrew/Cellar/go/1.23.4/libexec'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='local'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.23.4/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.23.4'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/bian/Library/Application Support/go/telemetry'
GCCGO='gccgo'
GOARM64='v8.0'
AR='ar'
CC='cc'
CXX='c++'
CGO_ENABLED='1'
GOMOD='/Users/bian/code/lint-test/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/dt/w56r82l955v2r8yndkc5p2lc0000gn/T/go-build1485231540=/tmp/go-build -gno-record-gcc-switches -fno-common'

Verbose output of running

$ golangci-lint cache clean
$ golangci-lint run -v
INFO golangci-lint has version 1.63.2 built with go1.23.4 from 15412b30 on 2025-01-02T12:43:20Z
INFO [config_reader] Config search paths: [./ /Users/bian/code/lint-test /Users/bian/code /Users/bian /Users /]
INFO [config_reader] Used config file .golangci.yaml
INFO [lintersdb] Active 1 linters: [gofumpt]
INFO [loader] Go packages loading at mode 8199 (name|compiled_files|files) took 89.19125ms
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 194.416µs
INFO [linters_context/goanalysis] analyzers took 103.957µs with top 10 stages: gofumpt: 89.666µs, typecheck: 14.291µs
ERRO [runner] Panic: gofumpt: package "main" (isInitialPkg: true, needAnalyzeSource: true): invalid line number 11 (should be < 10): goroutine
161 [running]:
runtime/debug.Stack()
        runtime/debug/stack.go:26 +0x64
github.com/golangci/golangci-lint/pkg/goanalysis.(*action).analyzeSafe.func1()
        github.com/golangci/golangci-lint/pkg/goanalysis/runner_action.go:50 +0x21c
panic({0x101943620?, 0x1400067c1e0?})
        runtime/panic.go:785 +0x124
go/token.(*File).LineStart(0x0?, 0x1015cdc40?)
        go/token/position.go:232 +0x178
github.com/golangci/golangci-lint/pkg/golinters/internal.toDiagnostic(0x14000169140, {0xb, 0xb, {0x0, 0x0, 0x0}}, 0x0)
        github.com/golangci/golangci-lint/pkg/golinters/internal/diff.go:254 +0x5c
github.com/golangci/golangci-lint/pkg/golinters/internal.ExtractDiagnosticFromPatch(0x1400067a000, 0x14001190000, {0x14000f1a900, 0x82}, 0x1400
058e180)
        github.com/golangci/golangci-lint/pkg/golinters/internal/diff.go:245 +0x334
github.com/golangci/golangci-lint/pkg/golinters/gofumpt.runGofumpt(0x1400058e180, 0x1400067a000, {0x101b3f780, 0x1026206a0}, {{0x1400060ff60, 0
x8}, {0x0, 0x0}, 0x0})
        github.com/golangci/golangci-lint/pkg/golinters/gofumpt/gofumpt.go:89 +0x324
github.com/golangci/golangci-lint/pkg/golinters/gofumpt.New.func1.1(0x1000000000a?)
        github.com/golangci/golangci-lint/pkg/golinters/gofumpt/gofumpt.go:52 +0x48
github.com/golangci/golangci-lint/pkg/goanalysis.(*action).analyze.func3(0x14000ff9608, 0x1400067a000)
        github.com/golangci/golangci-lint/pkg/goanalysis/runner_checker.go:182 +0xd0
github.com/golangci/golangci-lint/pkg/goanalysis.(*action).analyze(0x14000ff9608)
        github.com/golangci/golangci-lint/pkg/goanalysis/runner_checker.go:208 +0x97c
github.com/golangci/golangci-lint/pkg/timeutils.(*Stopwatch).TrackStage(0x14001047c20, {0x1015c35d1, 0x7}, 0x140004c6730)
        github.com/golangci/golangci-lint/pkg/timeutils/stopwatch.go:111 +0x44
github.com/golangci/golangci-lint/pkg/goanalysis.(*action).analyzeSafe(0x100f88520?)
        github.com/golangci/golangci-lint/pkg/goanalysis/runner_action.go:54 +0x70
github.com/golangci/golangci-lint/pkg/goanalysis.(*loadingPackage).analyze.func2(0x14000ff9608)
        github.com/golangci/golangci-lint/pkg/goanalysis/runner_loadingpackage.go:83 +0xac
created by github.com/golangci/golangci-lint/pkg/goanalysis.(*loadingPackage).analyze in goroutine 80
        github.com/golangci/golangci-lint/pkg/goanalysis/runner_loadingpackage.go:78 +0x174
WARN [runner] Can't run linter goanalysis_metalinter: goanalysis_metalinter: gofumpt: package "main" (isInitialPkg: true, needAnalyzeSource: true): invalid line number 11 (should be < 10)
INFO [runner] processing took 1.249µs with stages: max_same_issues: 375ns, cgo: 167ns, exclude: 125ns, skip_dirs: 125ns, max_from_linter: 83ns, invalid_issue: 42ns, skip_files: 42ns, path_prettifier: 42ns, identifier_marker: 42ns, exclude-rules: 42ns, filename_unadjuster: 41ns, path_shortener: 41ns, diff: 41ns, source_code: 41ns, uniq_by_line: 0s, severity-rules: 0s, nolint: 0s, max_per_file_from_linter: 0s, fixer: 0s, path_prefixer: 0s, autogenerated_exclude: 0s, sort_results: 0s
INFO [runner] linters took 540.458µs with stages: goanalysis_metalinter: 492.792µs
ERRO Running error: can't run linter goanalysis_metalinter
goanalysis_metalinter: gofumpt: package "main" (isInitialPkg: true, needAnalyzeSource: true): invalid line number 11 (should be < 10)
INFO Memory: 3 samples, avg is 27.4MB, max is 27.4MB
INFO Execution took 101.097875ms

A minimal reproducible example or link to a public repository

package main

import (
	"fmt"
)

func main() {
	fmt.Println("hello world")
}


Validation

  • Yes, I've included all information above (version, config, etc.).

Supporter

@rbrady98 rbrady98 added the bug Something isn't working label Jan 2, 2025
Copy link

boring-cyborg bot commented Jan 2, 2025

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

@rbrady98 rbrady98 changed the title panic out of range when autofixing panic out of range when diagnostic is on final line Jan 2, 2025
@ldez ldez self-assigned this Jan 2, 2025
@ldez ldez closed this as completed in #5287 Jan 2, 2025
@ldez ldez mentioned this issue Jan 2, 2025
7 tasks
dgn added a commit to istio/tools that referenced this issue Jan 7, 2025
1.63.1 has a few bugs that affected us (especially
golangci/golangci-lint#5285).
istio-testing pushed a commit to istio/tools that referenced this issue Jan 7, 2025
1.63.1 has a few bugs that affected us (especially
golangci/golangci-lint#5285).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants