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

Linter throwing Panic #13

Closed
HirdrWit opened this issue Apr 1, 2021 · 7 comments
Closed

Linter throwing Panic #13

HirdrWit opened this issue Apr 1, 2021 · 7 comments
Assignees
Labels
question Further information is requested

Comments

@HirdrWit
Copy link

HirdrWit commented Apr 1, 2021

Linter crashed while building in Jenkins.

[2021-03-31T16:06:22.161Z] + golangci-lint run -c ./golangci.yaml [2021-03-31T16:06:48.663Z] level=warning msg="[linters context] Panic: exportloopref: package \"loggingapi\" (isInitialPkg: true, needAnalyzeSource: true): runtime error: invalid memory address or nil pointer dereference: goroutine 8231 [running]:\nruntime/debug.Stack(0xf2d9bd, 0x3c, 0xc002296578)\n\truntime/debug/stack.go:24 +0x9f\ngithub.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func1(0xc0038a1390)\n\tgithub.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner.go:508 +0x1be\npanic(0xd76f60, 0x1541d70)\n\truntime/panic.go:965 +0x1b9\ngo/ast.(*Object).Pos(0x0, 0xc002296c20)\n\tgo/ast/scope.go:93 +0x29\ngithub.com/kyoh86/exportloopref.(*Searcher).isVar(0xc002296bf0, 0x10429d8, 0xc00c41eff0, 0x104b930, 0xc00f0cc6a0, 0xc00c41eff0)\n\tgithub.com/kyoh86/exportloopref@v0.1.8/exportloopref.go:275 +0xb0\ngithub.com/kyoh86/exportloopref.(*Searcher).checkUnaryExpr(0xc002296bf0, 0xc00f0cc700, 0xc0000d6200, 0xd, 0x10, 0x0, 0x0, 0xf5a401)\n\tgithub.com/kyoh86/exportloopref@v0.1.8/exportloopref.go:251 +0x3b8\ngithub.com/kyoh86/exportloopref.(*Searcher).Check(0xc002296bf0, 0x1042c58, 0xc00f0cc700, 0xc0000d6200, 0xd, 0x10, 0x0, 0x0, 0xc002296a01)\n\tgithub.com/kyoh86/exportloopref@v0.1.8/exportloopref.go:100 +0xee\ngithub.com/kyoh86/exportloopref.run.func1(0x1042c58, 0xc00f0cc700, 0x1, 0xc0000d6200, 0xd, 0x10, 0x1)\n\tgithub.com/kyoh86/exportloopref@v0.1.8/exportloopref.go:46 +0x8c\ngolang.org/x/tools/go/ast/inspector.(*Inspector).WithStack(0xc01ced4090, 0xc002296c80, 0x5, 0x5, 0xc00aab9c08)\n\tgolang.org/x/tools@v0.1.0/go/ast/inspector/inspector.go:126 +0x142\ngithub.com/kyoh86/exportloopref.run(0xc00dcfdee0, 0x592ac3264, 0x164e260, 0xc00871dbb8, 0x2)\n\tgithub.com/kyoh86/exportloopref@v0.1.8/exportloopref.go:45 +0x28b\ngithub.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyze(0xc0038a1390)\n\tgithub.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner.go:590 +0xa85\ngithub.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func2()\n\tgithub.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner.go:512 +0x2a\ngithub.com/golangci/golangci-lint/pkg/timeutils.(*Stopwatch).TrackStage(0xc001e58500, 0xee921b, 0xd, 0xc0037cb770)\n\tgithub.com/golangci/golangci-lint/pkg/timeutils/stopwatch.go:111 +0x4d\ngithub.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe(0xc0038a1390)\n\tgithub.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner.go:511 +0x91\ngithub.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze.func2(0xc00c73be50, 0xc0038a1390)\n\tgithub.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner.go:1059 +0x65\ncreated by github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze\n\tgithub.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner.go:1054 +0x316\n" [2021-03-31T16:06:48.663Z] level=warning msg="[runner] Can't run linter goanalysis_metalinter: goanalysis_metalinter: exportloopref: package \"loggingapi\" (isInitialPkg: true, needAnalyzeSource: true): runtime error: invalid memory address or nil pointer dereference" [2021-03-31T16:06:48.663Z] level=error msg="Running error: goanalysis_metalinter: exportloopref: package \"loggingapi\" (isInitialPkg: true, needAnalyzeSource: true): runtime error: invalid memory address or nil pointer dereference" script returned exit code 3

@kyoh86
Copy link
Owner

kyoh86 commented Apr 2, 2021

Give me a code to reproduce it.

@kyoh86 kyoh86 added the question Further information is requested label Apr 2, 2021
@kud202
Copy link

kud202 commented Sep 9, 2022

@kyoh86 I ran into this, here's a minimal test case I could form:

https://github.com/kud202/testExportRef

@kud202
Copy link

kud202 commented Sep 9, 2022

It looks like Obj is nil for some reason when the variable is defined outside the file:

https://github.com/kyoh86/exportloopref/blob/main/exportloopref.go#L301

@kyoh86
Copy link
Owner

kyoh86 commented Oct 4, 2022

Sorry for late. I cannot check it out up to 2 weeks ahead.

@kud202
Copy link

kud202 commented Oct 10, 2022

No problem, take a look when you are free.

Also, after looking at it a bit more, I think it might be safe to do a just a nil check there. I can PR that. Because from what I can tell that value is only nil if the variable if A] there is a syntax error and B] the variable is defined outside the file. In either case, it cannot be a local variable, so it might be safe to return false in the function if that value is nil.

But I hope you get it eventually 👍

kyoh86 added a commit that referenced this issue Nov 16, 2022
kyoh86 added a commit that referenced this issue Nov 16, 2022
@kyoh86 kyoh86 closed this as completed in 1977096 Nov 16, 2022
@kyoh86
Copy link
Owner

kyoh86 commented Nov 16, 2022

@kud202 @HirdrWit
Sorry for late.
It's fixed in v0.1.11

@kud202
Copy link

kud202 commented Nov 16, 2022

Thanks !

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

No branches or pull requests

3 participants