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: panic in sortImports #50329

Closed
hongshengjie opened this issue Dec 22, 2021 · 3 comments
Closed

x/tools/gopls: panic in sortImports #50329

hongshengjie opened this issue Dec 22, 2021 · 3 comments
Labels
FrozenDueToAge 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

@hongshengjie
Copy link

gopls version: v0.7.4
gopls flags:
update flags: proxy
extension version: 0.30.0
go version: 1.17.2
environment: Visual Studio Code darwin
initialization error: undefined
issue timestamp: Wed, 22 Dec 2021 06:52:22 GMT
restart history:
Wed, 22 Dec 2021 06:50:35 GMT: activation (enabled: true)

ATTENTION: PLEASE PROVIDE THE DETAILS REQUESTED BELOW.

Describe what you observed.

panic: invalid line number 16 (should be < 15)

goroutine 109 [running]:
go/token.(*File).MergeLine(0x140020a4180, 0x10)
	  position.go:158  0x210
golang.org/x/tools/internal/imports.sortImports({0x0, 0x0}, 0x1400159c5c0, 0x14000a4bf80)
	  sortimports.go:55  0x4f4
golang.org/x/tools/internal/imports.formatFile(0x1400159c5c0, 0x14000a4bf80, {0x140009bd000, 0x2eaa, 0x2eab}, 0x0, 0x14000ca2780)
	  imports.go:108  0x60
golang.org/x/tools/internal/imports.ApplyFixes({0x0, 0x0, 0x0}, {0x0, 0x0}, {0x140009bd000, 0x2eaa, 0x2eab}, 0x14000ca2780, 0x2)
	  imports.go:103  0x13c
golang.org/x/tools/internal/lsp/source.computeFixEdits({0x103a49260, 0x140002e9100}, 0x1400067cde0, 0x14000ca2780, {0x0, 0x0, 0x0})
	  format.go:179  0x15c
golang.org/x/tools/internal/lsp/source.computeImportEdits({0x103a49260, 0x140002e9100}, 0x1400067cde0, 0x14000ca2780)
	  format.go:124  0xd0
golang.org/x/tools/internal/lsp/source.AllImportsFixes.func1(0x14000ca2780)
	  format.go:105  0x58
golang.org/x/tools/internal/lsp/cache.(*importsState).runProcessEnvFunc(0x140001271a0, {0x103a24100, 0x140018dcc00}, 0x140002e9100, 0x1400152c440)
	  imports.go:109  0x5dc
golang.org/x/tools/internal/lsp/cache.(*snapshot).RunProcessEnvFunc(0x140002e9100, {0x103a24100, 0x140018dcc00}, 0x1400152c440)
	  view.go:332  0x4c
golang.org/x/tools/internal/lsp/source.AllImportsFixes({0x103a24058, 0x14000012340}, {0x103a49260, 0x140002e9100}, {0x103a2ead8, 0x14000f97740})
	  format.go:104  0x2e4
golang.org/x/tools/internal/lsp.(*Server).codeAction(0x14000548d80, {0x103a24058, 0x14000012340}, 0x14001602600)
	  code_action.go:97  0x804
golang.org/x/tools/internal/lsp.(*Server).CodeAction(0x14000548d80, {0x103a24058, 0x14000012340}, 0x14001602600)
	  server_gen.go:16  0x40
golang.org/x/tools/internal/lsp/protocol.serverDispatch({0x103a24058, 0x14000012340}, {0x103a4d090, 0x14000548d80}, 0x140018dc1e0, {0x103a242c0, 0x140000122c0})
	  tsserver.go:454  0x1cf0
golang.org/x/tools/internal/lsp/protocol.ServerHandler.func1({0x103a24058, 0x14000012340}, 0x140018dc1e0, {0x103a242c0, 0x140000122c0})
	  protocol.go:154  0x84
golang.org/x/tools/internal/lsp/lsprpc.handshaker.func1({0x103a24058, 0x14000012340}, 0x140018dc1e0, {0x103a242c0, 0x140000122c0})
	  lsprpc.go:506  0x8a4
golang.org/x/tools/internal/jsonrpc2.MustReplyHandler.func1({0x103a24058, 0x14000012340}, 0x1400032ad80, {0x103a242c0, 0x140000122c0})
	  handler.go:35  0xf4
golang.org/x/tools/internal/jsonrpc2.AsyncHandler.func1.2(0x140002727e0, 0x1400001fb30, 0x1400020ca50, {0x103a24058, 0x14000012340}, 0x1400032ad80, {0x103a242c0, 0x140000122c0})
	  handler.go:103  0x6c
created by golang.org/x/tools/internal/jsonrpc2.AsyncHandler.func1
	  handler.go:100  0x15c
[Error - 下午2:52:12] 

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>

@findleyr
Copy link
Contributor

Thank you for the report -- I haven't seen this before. Do you have any more information about what you were doing at the time of the crash?

@findleyr findleyr changed the title Dec 23, 2021
@findleyr findleyr transferred this issue from golang/vscode-go Dec 23, 2021
@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 Dec 23, 2021
@gopherbot gopherbot added this to the Unreleased milestone Dec 23, 2021
@findleyr findleyr modified the milestones: Unreleased, gopls/v0.7.5 Dec 23, 2021
@pjweinb
Copy link

pjweinb commented Jan 6, 2022

I cannot find an example that reproduces this. @hongshengjie , do you remember what the imports looked like when this happened? (It's possible to make sure it doesn't panic again, but it would be nice to understand what happend.)

@gopherbot
Copy link

Change https://golang.org/cl/376274 mentions this issue: internal/imports: avoid rare panic

rinchsan pushed a commit to rinchsan/gosimports that referenced this issue Aug 14, 2022
(*token.File)MergeLine() can panic. Add code to avoid the panic
and request information from users.

Fixes golang/go#50329

Change-Id: I9c10a5c6cbee4ff8a34321e77e32971f7e588cb5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/376274
Run-TryBot: Peter Weinberger <pjw@google.com>
Trust: Peter Weinberger <pjw@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
@golang golang locked and limited conversation to collaborators Jan 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge 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