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

x/tools/gopls: "missing Diagnostic.Code" assertion failure for unusedvariable analyzer #65578

Closed
unklnik opened this issue Feb 7, 2024 · 9 comments
Assignees
Labels
gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@unklnik
Copy link

unklnik commented Feb 7, 2024

gopls version: v0.15.0-pre.2/go1.22.0
gopls flags:
update flags: proxy
extension version: 2024.2.521
environment: Visual Studio Code win32
initialization error: undefined
issue timestamp: Wed, 07 Feb 2024 15:15:39 GMT
restart history:
Wed, 07 Feb 2024 15:15:04 GMT: activation (enabled: true)

ATTENTION: PLEASE PROVIDE THE DETAILS REQUESTED BELOW.

Describe what you observed.

Updated to Go 1.22.0 today and have been using Go Nightly for years this has not happened before. Gopls error popped up to say it lost connection to server.

Please attach the stack trace from the crash.
A window with the error message should have popped up in the lower half of your screen.
Please copy the stack trace and error messages from that window and paste it in this issue.
[Info - 5:15:04 PM] 2024/02/07 17:15:04 go info for D:\gamedev\003
(view type AdHocView)
(root dir D:\gamedev\003)
(go version go version go1.22.0 windows/amd64)
(build flags: [])
(go env: {GOOS:windows GOARCH:amd64 GOCACHE:C:\Users\unklnik\AppData\Local\go-build GOMODCACHE:C:\Users\unklnik\go\pkg\mod GOPATH:C:\Users\unklnik\go GOPRIVATE: GOFLAGS: GO111MODULE:auto GoVersion:22 GoVersionOutput:go version go1.22.0 windows/amd64
GOWORK: GOPACKAGESDRIVER:})
(env overlay: map[])

[Info - 5:15:04 PM] 2024/02/07 17:15:04 go/packages.Load golang/vscode-go#1
snapshot=0
directory=file:///D:/gamedev/003
query=[./ builtin]
packages=2

[Info - 5:15:04 PM] 2024/02/07 17:15:04 go/packages.Load golang/vscode-go#1: updating metadata for 58 packages

[Error - 5:15:08 PM] 2024/02/07 17:15:08 imports fixes: AllImportsFixes: D:\gamedev\003\003.go:9021:4: expected ';', found ':=' (and 22 more errors)
file="D:\gamedev\003\003.go"

[Error - 5:15:08 PM] Request textDocument/semanticTokens/full failed.
Message: semantic tokens: range D:\gamedev\003\003.go too large (424594 > 100000)
Code: 0
[Info - 5:15:19 PM] 2024/02/07 17:15:19 go info for D:\gamedev\003
(view type AdHocView)
(root dir D:\gamedev\003)
(go version go version go1.22.0 windows/amd64)
(build flags: [])
(go env: {GOOS:windows GOARCH:amd64 GOCACHE:C:\Users\unklnik\AppData\Local\go-build GOMODCACHE:C:\Users\unklnik\go\pkg\mod GOPATH:C:\Users\unklnik\go GOPRIVATE: GOFLAGS: GO111MODULE:auto GoVersion:22 GoVersionOutput:go version go1.22.0 windows/amd64
GOWORK: GOPACKAGESDRIVER:})
(env overlay: map[])

[Info - 5:15:20 PM] 2024/02/07 17:15:20 go/packages.Load golang/vscode-go#2
snapshot=0
directory=file:///D:/gamedev/003
query=[./ builtin]
packages=2

[Info - 5:15:20 PM] 2024/02/07 17:15:20 go/packages.Load golang/vscode-go#2: updating metadata for 58 packages

[Error - 5:15:22 PM] 2024/02/07 17:15:22 imports fixes: AllImportsFixes: D:\gamedev\003\003.go:9021:4: expected ';', found ':=' (and 22 more errors)
file="D:\gamedev\003\003.go"

[Error - 5:15:22 PM] Request textDocument/semanticTokens/full failed.
Message: semantic tokens: range D:\gamedev\003\003.go too large (424594 > 100000)
Code: 0
[Error - 5:15:23 PM] 2024/02/07 17:15:23 imports fixes: AllImportsFixes: D:\gamedev\003\003.go:9021:4: expected ';', found ':=' (and 22 more errors)
file="D:\gamedev\003\003.go"

[Error - 5:15:23 PM] Request textDocument/semanticTokens/full failed.
Message: semantic tokens: range D:\gamedev\003\003.go too large (424594 > 100000)
Code: 0
[Error - 5:15:24 PM] 2024/02/07 17:15:24 imports fixes: AllImportsFixes: D:\gamedev\003\003.go:9021:4: expected ';', found ':=' (and 22 more errors)
file="D:\gamedev\003\003.go"

[Error - 5:15:25 PM] 2024/02/07 17:15:24 imports fixes: AllImportsFixes: D:\gamedev\003\003.go:9021:4: expected ';', found ':=' (and 22 more errors)
file="D:\gamedev\003\003.go"

[Error - 5:15:25 PM] 2024/02/07 17:15:25 imports fixes: AllImportsFixes: D:\gamedev\003\003.go:9021:4: expected ';', found ':=' (and 22 more errors)
file="D:\gamedev\003\003.go"

[Error - 5:15:25 PM] 2024/02/07 17:15:25 imports fixes: AllImportsFixes: D:\gamedev\003\003.go:9021:4: expected ';', found ':=' (and 22 more errors)
file="D:\gamedev\003\003.go"

[Error - 5:15:27 PM] Request textDocument/semanticTokens/full failed.
Message: semantic tokens: range D:\gamedev\003\003.go too large (424591 > 100000)
Code: 0
[Error - 5:15:28 PM] Request textDocument/semanticTokens/range failed.
Message: context canceled
Code: 0
[Error - 5:15:28 PM] Request textDocument/semanticTokens/full failed.
Message: semantic tokens: range D:\gamedev\003\003.go too large (424593 > 100000)
Code: 0
[Error - 5:15:28 PM] 2024/02/07 17:15:28 imports fixes: AllImportsFixes: D:\gamedev\003\003.go:9021:4: expected ';', found ':=' (and 22 more errors)
file="D:\gamedev\003\003.go"

[Error - 5:15:32 PM] Request textDocument/semanticTokens/full failed.
Message: semantic tokens: range D:\gamedev\003\003.go too large (424596 > 100000)
Code: 0
[Error - 5:15:33 PM] Request textDocument/semanticTokens/full failed.
Message: semantic tokens: range D:\gamedev\003\003.go too large (424600 > 100000)
Code: 0
panic: missing Diagnostic.Code: cache.Diagnostic{URI:"file:///D:/gamedev/003/003.go", Range:9020:1-9020:2, Severity:Warning, Code:"default", CodeHref:"https://pkg.go.dev/golang.org/x/tools/gopls/internal/analysis/unusedvariable", Source:"unusedvariable", Message:"y declared and not used", Tags:[]protocol.DiagnosticTag(nil), Related:[]protocol.DiagnosticRelatedInformation(nil), BundledFixes:(*json.RawMessage)(nil), SuggestedFixes:[]cache.SuggestedFix(nil)}

goroutine 6048 [running]:
golang.org/x/tools/gopls/internal/cache.toSourceDiagnostic(0xc0002a9630, 0xc0015ad8d0)
C:/Users/unklnik/go/pkg/mod/golang.org/x/tools/gopls@v0.15.0-pre.2/internal/cache/errors.go:349 +0x999
golang.org/x/tools/gopls/internal/cache.(*Snapshot).Analyze(0x0, {0x1585628, 0xc0008fe060}, 0xc0008fe9c0, {0xc004bba008, 0xcc, 0x0?}, 0xc0001d8180)
C:/Users/unklnik/go/pkg/mod/golang.org/x/tools/gopls@v0.15.0-pre.2/internal/cache/analysis.go:470 +0x1534
golang.org/x/tools/gopls/internal/golang.Analyze({0x1585628, 0xc0008fe060}, 0xc00044e6c0, 0xc0008fe9c0, 0xc0001d8180)
C:/Users/unklnik/go/pkg/mod/golang.org/x/tools/gopls@v0.15.0-pre.2/internal/golang/diagnostics.go:42 +0x165
golang.org/x/tools/gopls/internal/server.(*server).diagnose.func6()
C:/Users/unklnik/go/pkg/mod/golang.org/x/tools/gopls@v0.15.0-pre.2/internal/server/diagnostics.go:499 +0xb2
created by golang.org/x/tools/gopls/internal/server.(*server).diagnose in goroutine 5907
C:/Users/unklnik/go/pkg/mod/golang.org/x/tools/gopls@v0.15.0-pre.2/internal/server/diagnostics.go:494 +0xfb7
[Info - 5:15:33 PM]
true
[Info - 5:15:34 PM] 2024/02/07 17:15:34 go info for D:\gamedev\003
(view type AdHocView)
(root dir D:\gamedev\003)
(go version go version go1.22.0 windows/amd64)
(build flags: [])
(go env: {GOOS:windows GOARCH:amd64 GOCACHE:C:\Users\unklnik\AppData\Local\go-build GOMODCACHE:C:\Users\unklnik\go\pkg\mod GOPATH:C:\Users\unklnik\go GOPRIVATE: GOFLAGS: GO111MODULE:auto GoVersion:22 GoVersionOutput:go version go1.22.0 windows/amd64
GOWORK: GOPACKAGESDRIVER:})
(env overlay: map[])

[Info - 5:15:34 PM] 2024/02/07 17:15:34 go/packages.Load golang/vscode-go#1
snapshot=0
directory=file:///D:/gamedev/003
query=[./ builtin]
packages=2

[Info - 5:15:34 PM] 2024/02/07 17:15:34 go/packages.Load golang/vscode-go#1: updating metadata for 58 packages

[Error - 5:15:34 PM] Request textDocument/semanticTokens/full failed.
Message: semantic tokens: range D:\gamedev\003\003.go too large (424600 > 100000)
Code: 0
panic: missing Diagnostic.Code: cache.Diagnostic{URI:"file:///D:/gamedev/003/003.go", Range:9020:1-9020:2, Severity:Warning, Code:"default", CodeHref:"https://pkg.go.dev/golang.org/x/tools/gopls/internal/analysis/unusedvariable", Source:"unusedvariable", Message:"y declared and not used", Tags:[]protocol.DiagnosticTag(nil), Related:[]protocol.DiagnosticRelatedInformation(nil), BundledFixes:(*json.RawMessage)(nil), SuggestedFixes:[]cache.SuggestedFix(nil)}

goroutine 1082 [running]:
golang.org/x/tools/gopls/internal/cache.toSourceDiagnostic(0xc00017e0a0, 0xc0050198d0)
C:/Users/unklnik/go/pkg/mod/golang.org/x/tools/gopls@v0.15.0-pre.2/internal/cache/errors.go:349 +0x999
golang.org/x/tools/gopls/internal/cache.(*Snapshot).Analyze(0x0, {0x1585628, 0xc00254fc20}, 0xc0025ba5a0, {0xc0006f0908, 0xcc, 0x0?}, 0xc0001467e0)
C:/Users/unklnik/go/pkg/mod/golang.org/x/tools/gopls@v0.15.0-pre.2/internal/cache/analysis.go:470 +0x1534
golang.org/x/tools/gopls/internal/golang.Analyze({0x1585628, 0xc00254fc20}, 0xc001a1c120, 0xc0025ba5a0, 0xc0001467e0)
C:/Users/unklnik/go/pkg/mod/golang.org/x/tools/gopls@v0.15.0-pre.2/internal/golang/diagnostics.go:42 +0x165
golang.org/x/tools/gopls/internal/server.(*server).diagnose.func6()
C:/Users/unklnik/go/pkg/mod/golang.org/x/tools/gopls@v0.15.0-pre.2/internal/server/diagnostics.go:499 +0xb2
created by golang.org/x/tools/gopls/internal/server.(*server).diagnose in goroutine 569
C:/Users/unklnik/go/pkg/mod/golang.org/x/tools/gopls@v0.15.0-pre.2/internal/server/diagnostics.go:494 +0xfb7
[Info - 5:15:35 PM]
true
[Info - 5:15:35 PM] 2024/02/07 17:15:35 go info for D:\gamedev\003
(view type AdHocView)
(root dir D:\gamedev\003)
(go version go version go1.22.0 windows/amd64)
(build flags: [])
(go env: {GOOS:windows GOARCH:amd64 GOCACHE:C:\Users\unklnik\AppData\Local\go-build GOMODCACHE:C:\Users\unklnik\go\pkg\mod GOPATH:C:\Users\unklnik\go GOPRIVATE: GOFLAGS: GO111MODULE:auto GoVersion:22 GoVersionOutput:go version go1.22.0 windows/amd64
GOWORK: GOPACKAGESDRIVER:})
(env overlay: map[])

[Info - 5:15:35 PM] 2024/02/07 17:15:35 go/packages.Load golang/vscode-go#1
snapshot=0
directory=file:///D:/gamedev/003
query=[./ builtin]
packages=2

[Info - 5:15:35 PM] 2024/02/07 17:15:35 go/packages.Load golang/vscode-go#1: updating metadata for 58 packages

[Error - 5:15:35 PM] Request textDocument/semanticTokens/full failed.
Message: semantic tokens: range D:\gamedev\003\003.go too large (424600 > 100000)
Code: 0
panic: missing Diagnostic.Code: cache.Diagnostic{URI:"file:///D:/gamedev/003/003.go", Range:9020:1-9020:2, Severity:Warning, Code:"default", CodeHref:"https://pkg.go.dev/golang.org/x/tools/gopls/internal/analysis/unusedvariable", Source:"unusedvariable", Message:"y declared and not used", Tags:[]protocol.DiagnosticTag(nil), Related:[]protocol.DiagnosticRelatedInformation(nil), BundledFixes:(*json.RawMessage)(nil), SuggestedFixes:[]cache.SuggestedFix(nil)}

goroutine 1041 [running]:
golang.org/x/tools/gopls/internal/cache.toSourceDiagnostic(0xc00000d8b0, 0xc001aad8d0)
C:/Users/unklnik/go/pkg/mod/golang.org/x/tools/gopls@v0.15.0-pre.2/internal/cache/errors.go:349 +0x999
golang.org/x/tools/gopls/internal/cache.(*Snapshot).Analyze(0x0, {0x1585628, 0xc002440090}, 0xc002440b40, {0xc001f68008, 0xcc, 0x6fa825?}, 0xc00017d2f0)
C:/Users/unklnik/go/pkg/mod/golang.org/x/tools/gopls@v0.15.0-pre.2/internal/cache/analysis.go:470 +0x1534
golang.org/x/tools/gopls/internal/golang.Analyze({0x1585628, 0xc002440090}, 0xc001984240, 0xc002440b40, 0xc00017d2f0)
C:/Users/unklnik/go/pkg/mod/golang.org/x/tools/gopls@v0.15.0-pre.2/internal/golang/diagnostics.go:42 +0x165
golang.org/x/tools/gopls/internal/server.(*server).diagnose.func6()
C:/Users/unklnik/go/pkg/mod/golang.org/x/tools/gopls@v0.15.0-pre.2/internal/server/diagnostics.go:499 +0xb2
created by golang.org/x/tools/gopls/internal/server.(*server).diagnose in goroutine 670
C:/Users/unklnik/go/pkg/mod/golang.org/x/tools/gopls@v0.15.0-pre.2/internal/server/diagnostics.go:494 +0xfb7
[Info - 5:15:36 PM]
true
[Info - 5:15:36 PM] 2024/02/07 17:15:36 go info for D:\gamedev\003
(view type AdHocView)
(root dir D:\gamedev\003)
(go version go version go1.22.0 windows/amd64)
(build flags: [])
(go env: {GOOS:windows GOARCH:amd64 GOCACHE:C:\Users\unklnik\AppData\Local\go-build GOMODCACHE:C:\Users\unklnik\go\pkg\mod GOPATH:C:\Users\unklnik\go GOPRIVATE: GOFLAGS: GO111MODULE:auto GoVersion:22 GoVersionOutput:go version go1.22.0 windows/amd64
GOWORK: GOPACKAGESDRIVER:})
(env overlay: map[])

[Info - 5:15:36 PM] 2024/02/07 17:15:36 go/packages.Load golang/vscode-go#1
snapshot=0
directory=file:///D:/gamedev/003
query=[./ builtin]
packages=2

[Info - 5:15:36 PM] 2024/02/07 17:15:36 go/packages.Load golang/vscode-go#1: updating metadata for 58 packages

[Error - 5:15:37 PM] Request textDocument/semanticTokens/full failed.
Message: semantic tokens: range D:\gamedev\003\003.go too large (424600 > 100000)
Code: 0
panic: missing Diagnostic.Code: cache.Diagnostic{URI:"file:///D:/gamedev/003/003.go", Range:9020:1-9020:2, Severity:Warning, Code:"default", CodeHref:"https://pkg.go.dev/golang.org/x/tools/gopls/internal/analysis/unusedvariable", Source:"unusedvariable", Message:"y declared and not used", Tags:[]protocol.DiagnosticTag(nil), Related:[]protocol.DiagnosticRelatedInformation(nil), BundledFixes:(*json.RawMessage)(nil), SuggestedFixes:[]cache.SuggestedFix(nil)}

goroutine 1106 [running]:
golang.org/x/tools/gopls/internal/cache.toSourceDiagnostic(0xc0001116d0, 0xc0025338d0)
C:/Users/unklnik/go/pkg/mod/golang.org/x/tools/gopls@v0.15.0-pre.2/internal/cache/errors.go:349 +0x999
golang.org/x/tools/gopls/internal/cache.(*Snapshot).Analyze(0x0, {0x1585628, 0xc0022a30b0}, 0xc0022a39e0, {0xc001e40d08, 0xcc, 0x0?}, 0xc0006300c0)
C:/Users/unklnik/go/pkg/mod/golang.org/x/tools/gopls@v0.15.0-pre.2/internal/cache/analysis.go:470 +0x1534
golang.org/x/tools/gopls/internal/golang.Analyze({0x1585628, 0xc0022a30b0}, 0xc0012d6000, 0xc0022a39e0, 0xc0006300c0)
C:/Users/unklnik/go/pkg/mod/golang.org/x/tools/gopls@v0.15.0-pre.2/internal/golang/diagnostics.go:42 +0x165
golang.org/x/tools/gopls/internal/server.(*server).diagnose.func6()
C:/Users/unklnik/go/pkg/mod/golang.org/x/tools/gopls@v0.15.0-pre.2/internal/server/diagnostics.go:499 +0xb2
created by golang.org/x/tools/gopls/internal/server.(*server).diagnose in goroutine 727
C:/Users/unklnik/go/pkg/mod/golang.org/x/tools/gopls@v0.15.0-pre.2/internal/server/diagnostics.go:494 +0xfb7
[Info - 5:15:37 PM]
true
[Info - 5:15:38 PM] 2024/02/07 17:15:38 go info for D:\gamedev\003
(view type AdHocView)
(root dir D:\gamedev\003)
(go version go version go1.22.0 windows/amd64)
(build flags: [])
(go env: {GOOS:windows GOARCH:amd64 GOCACHE:C:\Users\unklnik\AppData\Local\go-build GOMODCACHE:C:\Users\unklnik\go\pkg\mod GOPATH:C:\Users\unklnik\go GOPRIVATE: GOFLAGS: GO111MODULE:auto GoVersion:22 GoVersionOutput:go version go1.22.0 windows/amd64
GOWORK: GOPACKAGESDRIVER:})
(env overlay: map[])

[Info - 5:15:38 PM] 2024/02/07 17:15:38 go/packages.Load golang/vscode-go#1
snapshot=0
directory=file:///D:/gamedev/003
query=[./ builtin]
packages=2

[Info - 5:15:38 PM] 2024/02/07 17:15:38 go/packages.Load golang/vscode-go#1: updating metadata for 58 packages

[Error - 5:15:38 PM] Request textDocument/semanticTokens/full failed.
Message: semantic tokens: range D:\gamedev\003\003.go too large (424600 > 100000)
Code: 0
panic: missing Diagnostic.Code: cache.Diagnostic{URI:"file:///D:/gamedev/003/003.go", Range:9020:1-9020:2, Severity:Warning, Code:"default", CodeHref:"https://pkg.go.dev/golang.org/x/tools/gopls/internal/analysis/unusedvariable", Source:"unusedvariable", Message:"y declared and not used", Tags:[]protocol.DiagnosticTag(nil), Related:[]protocol.DiagnosticRelatedInformation(nil), BundledFixes:(*json.RawMessage)(nil), SuggestedFixes:[]cache.SuggestedFix(nil)}

goroutine 751 [running]:
golang.org/x/tools/gopls/internal/cache.toSourceDiagnostic(0xc00022b720, 0xc0020d18d0)
C:/Users/unklnik/go/pkg/mod/golang.org/x/tools/gopls@v0.15.0-pre.2/internal/cache/errors.go:349 +0x999
golang.org/x/tools/gopls/internal/cache.(*Snapshot).Analyze(0x0, {0x1585628, 0xc001ff8060}, 0xc001ff8990, {0xc002339b08, 0xcc, 0xc0004e8dc0?}, 0xc000532120)
C:/Users/unklnik/go/pkg/mod/golang.org/x/tools/gopls@v0.15.0-pre.2/internal/cache/analysis.go:470 +0x1534
golang.org/x/tools/gopls/internal/golang.Analyze({0x1585628, 0xc001ff8060}, 0xc001618240, 0xc001ff8990, 0xc000532120)
C:/Users/unklnik/go/pkg/mod/golang.org/x/tools/gopls@v0.15.0-pre.2/internal/golang/diagnostics.go:42 +0x165
golang.org/x/tools/gopls/internal/server.(*server).diagnose.func6()
C:/Users/unklnik/go/pkg/mod/golang.org/x/tools/gopls@v0.15.0-pre.2/internal/server/diagnostics.go:499 +0xb2
created by golang.org/x/tools/gopls/internal/server.(*server).diagnose in goroutine 697
C:/Users/unklnik/go/pkg/mod/golang.org/x/tools/gopls@v0.15.0-pre.2/internal/server/diagnostics.go:494 +0xfb7
[Error - 5:15:39 PM]

Failed to auto-collect gopls trace: incomplete panic trace.

gopls stats -anon { "DirStats": { "Files": 1047, "TestdataFiles": 0, "GoFiles": 0, "ModFiles": 0, "Dirs": 472 }, "GOARCH": "amd64", "GOOS": "windows", "GOPACKAGESDRIVER": "", "GOPLSCACHE": "", "GoVersion": "go1.22.0", "GoplsVersion": "v0.15.0-pre.2", "InitialWorkspaceLoadDuration": "86.2756ms", "MemStats": { "HeapAlloc": 2656184, "HeapInUse": 5251072, "TotalAlloc": 11889904 }, "WorkspaceStats": { "Files": { "Total": 0, "Largest": 0, "Errs": 0 }, "Views": [ { "GoCommandVersion": "go1.22.0", "AllPackages": { "Packages": 0, "LargestPackage": 0, "CompiledGoFiles": 0, "Modules": 0 }, "WorkspacePackages": { "Packages": 0, "LargestPackage": 0, "CompiledGoFiles": 0, "Modules": 0 }, "Diagnostics": 0 } ] } }

OPTIONAL: If you would like to share more information, you can attach your complete gopls logs.

NOTE: THESE MAY CONTAIN SENSITIVE INFORMATION ABOUT YOUR CODEBASE.
DO NOT SHARE LOGS IF YOU ARE WORKING IN A PRIVATE REPOSITORY.

<OPTIONAL: ATTACH LOGS HERE>

@unklnik
Copy link
Author

unklnik commented Feb 7, 2024

Uninstalled Go Nightly, cleared VS Code and Go caches and then reinstalled Go Nightly and this seems to be fine again.

@unklnik
Copy link
Author

unklnik commented Feb 7, 2024

Can close this issue as it just asked me to report automatically seems OK now

@unklnik unklnik closed this as completed Feb 7, 2024
@findleyr findleyr reopened this Feb 7, 2024
@findleyr
Copy link
Contributor

findleyr commented Feb 7, 2024

Thanks. We should not be encountering any panics, so will investigate. CC @adonovan

@unklnik
Copy link
Author

unklnik commented Feb 7, 2024

OK sorry to close 1st time posting issue here

@findleyr
Copy link
Contributor

findleyr commented Feb 7, 2024

No need to apologize, at all! Your issue will help us fix a panic that may affect other users. We were about to start promoting this prerelease, and now have an opportunity to fix before doing so.

@adonovan adonovan changed the title gopls: automated issue report (crash) > updated to Go 1.22.0 and using Go Nightly first time this has happened x/tools/gopls: "missing Diagnostic.Code" assertion failure for unusedvariable analyzer Feb 7, 2024
@adonovan
Copy link
Member

adonovan commented Feb 7, 2024

The assertion that failed ensures that all lazy fixes, whose TextEdits are empty when the diagnostic is reported and are computed later by a command, have a "category" aka Diagnostic.Code, as this is used as the fix name.

			// Ensure that the analyzer specifies a category for all its no-edit fixes.
			if diag.Code == "" || diag.Code == "default" {
				panic(fmt.Sprintf("missing Diagnostic.Code: %#v", *diag))
			}

Ideally we would assert this invariant in analysistest to ensure good coverage, but we can't do it unconditionally as the analyzer API doesn't require it. Perhaps we should set a backdoor flag for all x/tools analyzers for this stricter check.

Alternatively, we could ensure that gopls contains at least one tests for every different statement that reports a lazy fix, but that seems duplicative and hard to maintain because it requires internal knowledge of each analyzer (as it evolves).

@adonovan adonovan transferred this issue from golang/vscode-go Feb 7, 2024
@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Feb 7, 2024
@gopherbot gopherbot added this to the Unreleased milestone Feb 7, 2024
@findleyr
Copy link
Contributor

findleyr commented Feb 7, 2024

Shall we downgrade this panic to a bug.Report? We will see it anyway, and it seems recoverable.

I understand it's an internal bug, but we're near a release. Happy to promote it to panic after the release.

@adonovan
Copy link
Member

adonovan commented Feb 7, 2024

I've prepared a CL that moves the assertion into analysistest, but it didn't trigger for any of our analyzers. I think the analyzer is actually computing an eager fix containing an empty list of edits, which looks like a different bug.

We'll still be at the mercy of test coverage though, so, yes, I think we need to downgrade it to a bug.Report. I'll do that in my CL.

@adonovan adonovan self-assigned this Feb 7, 2024
@gopherbot
Copy link

Change https://go.dev/cl/562397 mentions this issue: gopls/internal/cache: fix crash in analysis

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

4 participants