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

runtime error: index out of range [-1] #46

Closed
gnuletik opened this issue May 27, 2024 · 3 comments · Fixed by #45
Closed

runtime error: index out of range [-1] #46

gnuletik opened this issue May 27, 2024 · 3 comments · Fixed by #45

Comments

@gnuletik
Copy link

gnuletik commented May 27, 2024

code sample:

// main.go
package main

import (
	"context"
	"log/slog"
	"os"
)

func main() {
	logger := slog.New(slog.NewTextHandler(os.Stdout, nil)).With(slog.String("app", "myapp"))

	err := run()
	if err != nil {
		logger.ErrorContext(context.Background(), "run failed", slog.Any("error", err))
		return
	}
}

func run() error {
	return nil
}
# .golangci.yaml
linters:
  enable:
    - sloglint
linters-settings:
  sloglint:
    attr-only: true
    context: "all"
    static-msg: true
    key-naming-case: snake
$ golangci-lint run ./...
ERRO [runner] Panic: sloglint: package "main" (isInitialPkg: true, needAnalyzeSource: true): runtime error: index out of range [-1]: goroutine 937 [running]:
runtime/debug.Stack()
	runtime/debug/stack.go:24 +0x64
github.com/golangci/golangci-lint/pkg/goanalysis.(*action).analyzeSafe.func1()
	github.com/golangci/golangci-lint/pkg/goanalysis/runner_action.go:109 +0x21c
panic({0x10525f4a0?, 0x14001159998?})
	runtime/panic.go:770 +0x124
go-simpler.org/sloglint.visit(0x14004bd1420, 0x14000a09e00, {0x1052e63a8?, 0x14004597600}, {0x0, 0x0, 0x0})
	go-simpler.org/sloglint@v0.7.0/sloglint.go:226 +0xe28
go-simpler.org/sloglint.run.func2({0x1052e63a8?, 0x14004597600?})
	go-simpler.org/sloglint@v0.7.0/sloglint.go:179 +0x48
golang.org/x/tools/go/ast/inspector.(*Inspector).Preorder(0x1400342a1f8, {0x140029e3c10?, 0x105b9c700?, 0x10413db3c?}, 0x140014edc20)
	golang.org/x/tools@v0.21.0/go/ast/inspector/inspector.go:82 +0x90
go-simpler.org/sloglint.run(0x14004bd1420, 0x14000a09e00)
	go-simpler.org/sloglint@v0.7.0/sloglint.go:178 +0x110
go-simpler.org/sloglint.New.func1(0x10514ae40?)
	go-simpler.org/sloglint@v0.7.0/sloglint.go:70 +0x1f0
github.com/golangci/golangci-lint/pkg/goanalysis.(*action).analyze(0x14001324960)
	github.com/golangci/golangci-lint/pkg/goanalysis/runner_action.go:191 +0x8c4
github.com/golangci/golangci-lint/pkg/goanalysis.(*action).analyzeSafe.func2()
	github.com/golangci/golangci-lint/pkg/goanalysis/runner_action.go:113 +0x20
github.com/golangci/golangci-lint/pkg/timeutils.(*Stopwatch).TrackStage(0x140014185f0, {0x104d443fe, 0x8}, 0x140010d5730)
	github.com/golangci/golangci-lint/pkg/timeutils/stopwatch.go:111 +0x44
github.com/golangci/golangci-lint/pkg/goanalysis.(*action).analyzeSafe(0x1046d9470?)
	github.com/golangci/golangci-lint/pkg/goanalysis/runner_action.go:112 +0x78
github.com/golangci/golangci-lint/pkg/goanalysis.(*loadingPackage).analyze.func2(0x14001324960)
	github.com/golangci/golangci-lint/pkg/goanalysis/runner_loadingpackage.go:80 +0xb0
created by github.com/golangci/golangci-lint/pkg/goanalysis.(*loadingPackage).analyze in goroutine 141
	github.com/golangci/golangci-lint/pkg/goanalysis/runner_loadingpackage.go:75 +0x184
WARN [runner] Can't run linter goanalysis_metalinter: goanalysis_metalinter: sloglint: package "main" (isInitialPkg: true, needAnalyzeSource: true): runtime error: index out of range [-1]
ERRO Running error: can't run linter goanalysis_metalinter
goanalysis_metalinter: sloglint: package "main" (isInitialPkg: true, needAnalyzeSource: true): runtime error: index out of range [-1]
$ golangci-lint --version
golangci-lint has version 1.59.0 built with go1.22.3 from 2059b18 on 2024-05-25T11:38:08Z
@rolinh
Copy link

rolinh commented May 27, 2024

Also affected with only static-msg: true as the config. Note that this error started happening with v0.7.0 and is thus a regression from v0.6.0.

@tigrato
Copy link
Contributor

tigrato commented May 27, 2024

PR #45 fixes this issue.

@tmzane
Copy link
Member

tmzane commented May 27, 2024

Hi, thank you for the report.

@tigrato thanks for the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants