Skip to content

gomodguard: Panic stack trace: goroutine 1 [running]:\nruntime/debug.Stack() & can't run linter goanalysis_metalinter: panic occurred #4242

Open
@honey-yogurt

Description

@honey-yogurt

Welcome

Description of the problem

This is my first time using golangci-lint, adding pre-commit to an existing project.
My go.mod file is not in the root directory of the project. I used the pre-commit-hook project to apply golangci-lint. After renaming the directory where go.mod is located, I encountered a problem with the title.
This is my project structure:
image

Version of golangci-lint

$ golangci-lint --version
golangci-lint has version v1.46.2 built from (unknown, mod sum: "h1:o90t/Xa6dhJbvy8Bz2RpzUXqrkigp19DLStMolTZbyo=") on (unknown)

Configuration

# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
    - repo: https://github.com/pre-commit/pre-commit-hooks
      rev: v4.3.0
      hooks:
          - id: trailing-whitespace
          - id: end-of-file-fixer
          - id: check-yaml
          - id: check-added-large-files
    - repo: https://github.com/golangci/golangci-lint
      rev: v1.55.2
      hooks:
          - id: golangci-lint
    - repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook
      rev: v9.10.0
      hooks:
          - id: commitlint
            stages: [ commit-msg ]
            additional_dependencies: [ '@commitlint/config-conventional' ]

Go environment

$ go version && go env
go version go1.20.7 windows/amd64

set GO111MODULE=on
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\DELL\AppData\Local\go-build
set GOENV=C:\Users\DELL\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\DELL\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\DELL\go
set GOPRIVATE=
set GOPROXY=https://goproxy.cn,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.20.7
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=NUL
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=C:\Users\DELL\AppData\Local\Temp\go-build3470650649=/tmp/go-build -gno-record-gcc-switches

Verbose output of running

$ golangci-lint cache clean
$ golangci-lint run -v
[WARNING] Unstaged files detected.
[INFO] Stashing unstaged files to C:\Users\DELL\.cache\pre-commit\patch1702005891-24412.
trim trailing whitespace.................................................Passed
fix end of files.........................................................Passed
check yaml...........................................(no files to check)Skipped
check for added large files..............................................Passed
golangci-lint............................................................Failed
- hook id: golangci-lint
- exit code: 3
level=warning msg="[runner] The linter 'interfacer' is deprecated (since v1.38.0) due to: The repository of the linter has been archived by the owner. "
level=warning msg="[runner] The linter 'structcheck' is deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter. Replaced by unused."
level=warning msg="[runner] The linter 'deadcode' is deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter. Replaced by unused."
level=warning msg="[runner] The linter 'golint' is deprecated (since v1.41.0) due to: The repository of the linter has been archived by the owner. Replaced by revive."
level=warning msg="[runner] The linter 'varcheck' is deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter. Replaced by unused."
level=warning msg="[runner] The linter 'maligned' is deprecated (since v1.38.0) due to: The repository of the linter has been archived by the owner. Replaced by govet 'fieldalignment'."
level=error msg="[runner] Panic stack trace: goroutine 1 [running]:\nruntime/debug.Stack()\n\tC:/Program Files/Go/src/runtime/debug/stack.go:24 +0x65\ngithub.com/golangci/golangci-lint/pkg/lint.(*Runner).runLinterSafe.func1()\n\tC:/Users/DELL/.cache/pre-commit/repoyc5ufnm2/pkg/lint/runner.go:126 +0x28d\npanic({0x1b05560, 0x26657c0})\n\tC:/Program Files/Go/src/runtime/panic.go:884 +0x213\ngithub.com/ryancurrah/gomodguard.(*Processor).SetBlockedModules(0xc0023bbed8)\n\tC:/Users/DELL/.cache/pre-commit/repoyc5ufnm2/golangenv-system/pkg/mod/github.com/ryancurrah/[email protected]/processor.go:146 +0x5e\ngithub.com/ryancurrah/gomodguard.NewProcessor(0xc000a60540)\n\tC:/Users/DELL/.cache/pre-commit/repoyc5ufnm2/golangenv-system/pkg/mod/github.com/ryancurrah/[email protected]/processor.go:68 +0x170\ngithub.com/golangci/golangci-lint/pkg/golinters.NewGomodguard.func1(0xc0001ba770)\n\tC:/Users/DELL/.cache/pre-commit/repoyc5ufnm2/pkg/golinters/gomodguard.go:68 +0x45\ngithub.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*Linter).preRun(0xc000a39f80, 0xc00111f5e8?)\n\tC:/Users/DELL/.cache/pre-commit/repoyc5ufnm2/pkg/golinters/goanalysis/linter.go:157 +0xe2\ngithub.com/golangci/golangci-lint/pkg/golinters/goanalysis.MetaLinter.Run({{0xc00068ec00, 0x25, 0x40}, 0xc000b7cf30}, {0xc00007c800?, 0xc0006869a0?}, 0x0?)\n\tC:/Users/DELL/.cache/pre-commit/repoyc5ufnm2/pkg/golinters/goanalysis/metalinter.go:26 +0xa5\ngithub.com/golangci/golangci-lint/pkg/lint.(*Runner).runLinterSafe(0x3?, {0x1ecbe68?, 0xc000a59c50?}, 0xc0001ba770, 0xc000175900)\n\tC:/Users/DELL/.cache/pre-commit/repoyc5ufnm2/pkg/lint/runner.go:131 +0xcf\ngithub.com/golangci/golangci-lint/pkg/lint.Runner.Run.func1()\n\tC:/Users/DELL/.cache/pre-commit/repoyc5ufnm2/pkg/lint/runner.go:215 +0x65\ngithub.com/golangci/golangci-lint/pkg/timeutils.(*Stopwatch).TrackStage(0xc0007c4190, {0x1cd745f, 0x15}, 0xc00111f940)\n\tC:/Users/DELL/.cache/pre-commit/repoyc5ufnm2/pkg/timeutils/stopwatch.go:111 +0x4a\ngithub.com/golangci/golangci-lint/pkg/lint.Runner.Run({{0xc0006869a0, 0x15, 0x15}, {0x1ed1750, 0xc0008b2060}}, {0x1ecbe68, 0xc000a59c50}, {0xc00000b378, 0x1, 0x1}, ...)\n\tC:/Users/DELL/.cache/pre-commit/repoyc5ufnm2/pkg/lint/runner.go:214 +0x2ce\ngithub.com/golangci/golangci-lint/pkg/commands.(*Executor).runAnalysis(0xc000167200, {0x1ecbe68, 0xc000a59c50}, {0xc000a59bc0?, 0x45ec1606ad?, 0xc154c14c0e2e0334?})\n\tC:/Users/DELL/.cache/pre-commit/repoyc5ufnm2/pkg/commands/run.go:358 +0x611\ngithub.com/golangci/golangci-lint/pkg/commands.(*Executor).runAndPrint(0xc000167200, {0x1ecbe68, 0xc000a59c50}, {0xc000a59bc0, 0x0, 0x3})\n\tC:/Users/DELL/.cache/pre-commit/repoyc5ufnm2/pkg/commands/run.go:393 +0x1dd\ngithub.com/golangci/golangci-lint/pkg/commands.(*Executor).executeRun(0xc000167200, 0x0?, {0xc000a59bc0, 0x0, 0x3})\n\tC:/Users/DELL/.cache/pre-commit/repoyc5ufnm2/pkg/commands/run.go:510 +0x24f\ngithub.com/spf13/cobra.(*Command).execute(0xc000005200, {0xc000a59b60, 0x3, 0x3})\n\tC:/Users/DELL/.cache/pre-commit/repoyc5ufnm2/golangenv-system/pkg/mod/github.com/spf13/[email protected]/command.go:944 +0x847\ngithub.com/spf13/cobra.(*Command).ExecuteC(0xc000004f00)\n\tC:/Users/DELL/.cache/pre-commit/repoyc5ufnm2/golangenv-system/pkg/mod/github.com/spf13/[email protected]/command.go:1068 +0x3bd\ngithub.com/spf13/cobra.(*Command).Execute(...)\n\tC:/Users/DELL/.cache/pre-commit/repoyc5ufnm2/golangenv-system/pkg/mod/github.com/spf13/[email protected]/command.go:992\ngithub.com/golangci/golangci-lint/pkg/commands.(*Executor).Execute(...)\n\tC:/Users/DELL/.cache/pre-commit/repoyc5ufnm2/pkg/commands/executor.go:151\nmain.main()\n\tC:/Users/DELL/.cache/pre-commit/repoyc5ufnm2/cmd/golangci-lint/main.go:41 +0x1de\n"
level=warning msg="[runner] Can't run linter goanalysis_metalinter: panic occurred: runtime error: invalid memory address or nil pointer dereference"
level=error msg="Running error: 1 error occurred:\n\t* can't run linter goanalysis_metalinter: panic occurred: runtime error: invalid memory address or nil pointer dereference\n\n"
[INFO] Restored changes from C:\Users\DELL\.cache\pre-commit\patch1702005891-24412.

A minimal reproducible example or link to a public repository

code:

package main

import (
	"crypto/ecdsa"
	"crypto/elliptic"
	"crypto/rand"
	"fmt"
	"net/http"
	"time"

	"github.com/gin-gonic/gin"
)

func main() {

	r := gin.Default()

	r.GET("/health", func(c *gin.Context) {
		// 随便处理一些逻辑,以便于调试
		start := time.Now()
		priv, err := randomPrivateKey()
		if err != nil {
			fmt.Println("err", err)
		}
		fmt.Printf("%+v \n", priv)
		fmt.Println("time-consuming", time.Now().Sub(start))
		c.String(http.StatusOK, "I am ok!")
	})
	r.Run(":8000")
}

func randomPrivateKey() (*ecdsa.PrivateKey, error) {
	// 选择椭圆曲线类型
	curve := elliptic.P256()
	// 生成私钥
	privateKey, err := ecdsa.GenerateKey(curve, rand.Reader)
	if err != nil {
		return nil, err
	}
	return privateKey, nil
}

go.mod:

module delve

go 1.20

require github.com/gin-gonic/gin v1.9.1

require (
	github.com/bytedance/sonic v1.9.1 // indirect
	github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
	github.com/gabriel-vasile/mimetype v1.4.2 // indirect
	github.com/gin-contrib/sse v0.1.0 // indirect
	github.com/go-playground/locales v0.14.1 // indirect
	github.com/go-playground/universal-translator v0.18.1 // indirect
	github.com/go-playground/validator/v10 v10.14.0 // indirect
	github.com/goccy/go-json v0.10.2 // indirect
	github.com/json-iterator/go v1.1.12 // indirect
	github.com/klauspost/cpuid/v2 v2.2.4 // indirect
	github.com/leodido/go-urn v1.2.4 // indirect
	github.com/mattn/go-isatty v0.0.19 // indirect
	github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
	github.com/modern-go/reflect2 v1.0.2 // indirect
	github.com/pelletier/go-toml/v2 v2.0.8 // indirect
	github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
	github.com/ugorji/go/codec v1.2.11 // indirect
	golang.org/x/arch v0.3.0 // indirect
	golang.org/x/crypto v0.9.0 // indirect
	golang.org/x/net v0.10.0 // indirect
	golang.org/x/sys v0.8.0 // indirect
	golang.org/x/text v0.9.0 // indirect
	google.golang.org/protobuf v1.30.0 // indirect
	gopkg.in/yaml.v3 v3.0.1 // indirect
)

Validation

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdependenciesRelates to an upstream dependency

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions