Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Panic when checking code with a pointer to a type alias #256

Closed
mihaip opened this issue Oct 17, 2024 · 3 comments
Closed

Panic when checking code with a pointer to a type alias #256

mihaip opened this issue Oct 17, 2024 · 3 comments

Comments

@mihaip
Copy link

mihaip commented Oct 17, 2024

We're using errcheck v1.7.0 via golangci-lint on Go 1.23.2, and encountered this error when upgrading a dependency:

level=error msg="[runner] Panic: errcheck: package \"voice\" (isInitialPkg: true, needAnalyzeSource: true): cannot get Field of a type that is not a struct, got a *types.Alias: goroutine 54856 [running]:
runtime/debug.Stack()
	/opt/hostedtoolcache/go/1.23.2/x64/src/runtime/debug/stack.go:26 +0x5e
github.com/golangci/golangci-lint/pkg/goanalysis.(*action).analyzeSafe.func1()
	/tmp/custom-gcl2417513237/golangci-lint/pkg/goanalysis/runner_action.go:109 +0x277
panic({0x190e000?, 0xc02638d2c0?})
	/opt/hostedtoolcache/go/1.23.2/x64/src/runtime/panic.go:785 +0x132
github.com/kisielk/errcheck/errcheck.getTypeAtFieldIndex({0x1e5dce0?, 0xc058a61920?}, 0x49?)
	/home/runner/go/pkg/mod/github.com/kisielk/errcheck@v1.7.0/errcheck/embedded_walker.go:90 +0xdd
github.com/kisielk/errcheck/errcheck.walkThroughEmbeddedInterfaces(0x19a42a0?)
	/home/runner/go/pkg/mod/github.com/kisielk/errcheck@v1.7.0/errcheck/embedded_walker.go:49 +0x8e
github.com/kisielk/errcheck/errcheck.(*visitor).namesForExcludeCheck(0xc04338fa90, 0xc00f90c380?)
	/home/runner/go/pkg/mod/github.com/kisielk/errcheck@v1.7.0/errcheck/errcheck.go:362 +0x165
github.com/kisielk/errcheck/errcheck.(*visitor).excludeCall(0xc04338fa90, 0xc04338fa90?)
	/home/runner/go/pkg/mod/github.com/kisielk/errcheck@v1.7.0/errcheck/errcheck.go:401 +0x72
github.com/kisielk/errcheck/errcheck.(*visitor).ignoreCall(0xc04338fa90, 0xc00f90c380)
	/home/runner/go/pkg/mod/github.com/kisielk/errcheck@v1.7.0/errcheck/errcheck.go:413 +0x2c
github.com/kisielk/errcheck/errcheck.(*visitor).Visit(0xc04338fa90, {0x1e5d5b8?, 0xc060ef9f50})
	/home/runner/go/pkg/mod/github.com/kisielk/errcheck@v1.7.0/errcheck/errcheck.go:560 +0x137
go/ast.Walk({0x1e572e0?, 0xc04338fa90?}, {0x1e5d5b8, 0xc060ef9f50})
	/opt/hostedtoolcache/go/1.23.2/x64/src/go/ast/walk.go:34 +0x4c
go/ast.walkList[...](...)
	/opt/hostedtoolcache/go/1.23.2/x64/src/go/ast/walk.go:21
go/ast.Walk({0x1e572e0?, 0xc04338fa90?}, {0x1e5d090, 0xc01dbd8a50})
	/opt/hostedtoolcache/go/1.23.2/x64/src/go/ast/walk.go:211 +0x30ad
go/ast.Walk({0x1e572e0?, 0xc04338fa90?}, {0x1e5b8a8, 0xc01dbd8a80})
	/opt/hostedtoolcache/go/1.23.2/x64/src/go/ast/walk.go:332 +0xf7c
go/ast.walkList[...](...)
	/opt/hostedtoolcache/go/1.23.2/x64/src/go/ast/walk.go:21
go/ast.Walk({0x1e572e0?, 0xc04338fa90?}, {0x1e5b6e0, 0xc02238d180})
	/opt/hostedtoolcache/go/1.23.2/x64/src/go/ast/walk.go:341 +0x3585
github.com/kisielk/errcheck/errcheck.(*Checker).CheckPackage(0xc0003782a0, 0xc002f1cad8)
	/home/runner/go/pkg/mod/github.com/kisielk/errcheck@v1.7.0/errcheck/errcheck.go:235 +0x425
github.com/golangci/golangci-lint/pkg/golinters/errcheck.runErrCheck(0xc0002fcd20, 0xc058336620, 0xc0003782a0?)
	/tmp/custom-gcl2417513237/golangci-lint/pkg/golinters/errcheck/errcheck.go:82 +0xab
github.com/golangci/golangci-lint/pkg/golinters/errcheck.New.func1.1(0x19a4000?)
	/tmp/custom-gcl2417513237/golangci-lint/pkg/golinters/errcheck/errcheck.go:54 +0x49
github.com/golangci/golangci-lint/pkg/goanalysis.(*action).analyze(0xc007659d30)
	/tmp/custom-gcl2417513237/golangci-lint/pkg/goanalysis/runner_action.go:191 +0x9cd
github.com/golangci/golangci-lint/pkg/goanalysis.(*action).analyzeSafe.func2()
	/tmp/custom-gcl2417513237/golangci-lint/pkg/goanalysis/runner_action.go:113 +0x17
github.com/golangci/golangci-lint/pkg/timeutils.(*Stopwatch).TrackStage(0xc0028e2a00, {0x1b65691, 0x8}, 0xc0034aef48)
	/tmp/custom-gcl2417513237/golangci-lint/pkg/timeutils/stopwatch.go:111 +0x44
github.com/golangci/golangci-lint/pkg/goanalysis.(*action).analyzeSafe(0xc005a4a660?)
	/tmp/custom-gcl2417513237/golangci-lint/pkg/goanalysis/runner_action.go:112 +0x6e
github.com/golangci/golangci-lint/pkg/goanalysis.(*loadingPackage).analyze.func2(0xc007659d30)
	/tmp/custom-gcl2417513237/golangci-lint/pkg/goanalysis/runner_loadingpackage.go:82 +0xa5
created by github.com/golangci/golangci-lint/pkg/goanalysis.(*loadingPackage).analyze in goroutine 1034
	/tmp/custom-gcl2417513237/golangci-lint/pkg/goanalysis/runner_loadingpackage.go:77 +0x1e9
"

The dependency https://github.com/deepgram/deepgram-go-sdk, and we were bumping it from v1.4.0 to v.1.6.0. As part of that a type was deprecated and became an alias (source):

package websocketv1

...
// Client is an alias for WSCallback
// Deprecated: use WSCallback instead
type Client = WSCallback
package voice

import (
	listenapi "github.com/deepgram/deepgram-go-sdk/pkg/client/listen/v1/websocket"
)
...
type deepgramTranscriptionRequest struct {
	client *listenapi.Callback
}

#248 added support for type aliases - which is in the version that we're using, but perhaps there's an additional edge case here.

@dtcaciuc
Copy link
Collaborator

@JacobOaks Would you have some time to look into this?

@JacobOaks
Copy link
Contributor

JacobOaks commented Oct 17, 2024

The fix for types aliasing is included in the 1.8.0 release, so upgrading to that should fix the issue

@mihaip
Copy link
Author

mihaip commented Oct 17, 2024

Apologies, I must have misread the tags on the commit. We'll wait for golangci-lint to do a new release with the new version (saw that they picked it up in golangci/golangci-lint#5074).

@mihaip mihaip closed this as not planned Won't fix, can't repro, duplicate, stale Oct 17, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants