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/internal/lsp: panic: illegal Pos value #30155

Closed
pwaller opened this issue Feb 10, 2019 · 8 comments
Closed

x/tools/internal/lsp: panic: illegal Pos value #30155

pwaller opened this issue Feb 10, 2019 · 8 comments
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls.
Milestone

Comments

@pwaller
Copy link
Contributor

pwaller commented Feb 10, 2019

What version of Go are you using (go version)?

$ go version
go version devel +4b3f04c63b Thu Jan 10 18:15:48 2019 +0000 linux/amd64

Does this issue reproduce with the latest release?

I'm a couple of commits behind master on x/tools at time of writing (40960b6). I'm not testing on master because that fails due to #30154.

What did you do?

Compile gopls with -race. Use cmd/gopls/forward. Use vscode-go. I am working out of my $GOPATH using modules, and have GO111MODULE=on.

I was editing a fairly simple file at the time, it looked like this:

package main

import ir "github.com/llir/llvm/ir"

type foo struct {
	bar, baz, qux, mux, lux *ir.Func
}

What did you expect to see?

gopls continues to function.

What did you see?

Crash.

panic: illegal Pos value

goroutine 34 [running]:
go/token.(*File).Offset(...)
	/home/pwaller/.local/src/go/src/go/token/position.go:278
golang.org/x/tools/internal/lsp.toProtocolEdits(0xc05f078000, 0xc0a43ef780, 0x7e, 0x80, 0xc105442200, 0x1, 0x1, 0x1507de542, 0xc105442200, 0x1)
	/home/pwaller/.local/src/golang.org/x/tools/internal/lsp/format.go:56 +0x443
golang.org/x/tools/internal/lsp.organizeImports(0xa7c4e0, 0xc10527dd80, 0xa7b8a0, 0xc0000d1950, 0xc0fc360640, 0x43, 0xc10500c910, 0xc10500c8f8, 0xc0f7067880, 0x57018b, ...)
	/home/pwaller/.local/src/golang.org/x/tools/internal/lsp/imports.go:39 +0x38c
golang.org/x/tools/internal/lsp.(*server).CodeAction(0xc00007c640, 0xa7c4e0, 0xc10527dd80, 0xc07ee16540, 0xc07ee16540, 0x0, 0x0, 0x434760, 0x7f9992358a88)
	/home/pwaller/.local/src/golang.org/x/tools/internal/lsp/server.go:340 +0xd5
golang.org/x/tools/internal/lsp/protocol.serverHandler.func1(0xa7c4e0, 0xc10527dd80, 0xc0001d8000, 0xc10300bca0)
	/home/pwaller/.local/src/golang.org/x/tools/internal/lsp/protocol/server.go:283 +0x3380
golang.org/x/tools/internal/jsonrpc2.(*Conn).run(0xc0001d8000, 0xa7c520, 0xc0000bc010, 0x4849b1, 0xa7c520)
	/home/pwaller/.local/src/golang.org/x/tools/internal/jsonrpc2/jsonrpc2.go:327 +0x7e5
golang.org/x/tools/internal/jsonrpc2.NewConn.func4(0xc0001d8000, 0xa7c520, 0xc0000bc010)
	/home/pwaller/.local/src/golang.org/x/tools/internal/jsonrpc2/jsonrpc2.go:107 +0x51
created by golang.org/x/tools/internal/jsonrpc2.NewConn
	/home/pwaller/.local/src/golang.org/x/tools/internal/jsonrpc2/jsonrpc2.go:106 +0x261

I can't be sure the exact state the file was in at the time, nor my editor. I think there may have been a comma missing between qux and mux. I'm uncertain if I had added the import declaration yet. I have made a quick attempt to reproduce but did not have any luck.

/cc @stamblerre

@gopherbot gopherbot added this to the Unreleased milestone Feb 10, 2019
@stamblerre stamblerre self-assigned this Feb 11, 2019
@stamblerre
Copy link
Contributor

I expect that the possibly invalid file caused goimports to return an invalid result, and so the text edit ranges were incorrect, causing this nil pointer. If you do see this again and are able to find a repro case, that would be very helpful here.

@pjweinb
Copy link

pjweinb commented Mar 12, 2019

The same thing happened to me today. It's reproducible in situ, but the files are part of a large project.

@stamblerre stamblerre added gopls Issues related to the Go language server, gopls. and removed gopls Issues related to the Go language server, gopls. labels Mar 12, 2019
@pjweinb
Copy link

pjweinb commented Mar 13, 2019

The problem is at internal/lsp/format.go:50, where the edit.Range.End is 0. The code that causes this has a comment at the end of the file. The comment ends with
/
(That's <
></><\n>)
Adding a line after the comment that starts with // fixes it.

@pjweinb
Copy link

pjweinb commented Mar 13, 2019

Trying again: the comment at the end of the file is a blank, followed by a * followed by a slash followed by a newline. That comment causes edit.Range.End in lsp/format.go to be 0, which is illegal. Adding a // comment line to the end of the file fixes it.

@stamblerre
Copy link
Contributor

@pjweinb: the logic that causes this is going away in golang.org/cl/166884 with @ianthehat's new span library. I wonder if that will fix the issue. I'll try to repro after that CL goes in.

@Gandem
Copy link
Contributor

Gandem commented Mar 26, 2019

I'm consistently getting the error on 3ad05305c9b0 which is the latest master for x/tools.

Here's the stacktrace
panic: illegal Pos value

goroutine 18 [running]:
go/token.(*File).Offset(...)
	/usr/local/Cellar/go/1.12.1/libexec/src/go/token/position.go:278
golang.org/x/tools/internal/span.Range.Span(0xc00018c0c0, 0x827, 0x8df, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
	/Users/nayef.ghattas/go/pkg/mod/golang.org/x/tools@v0.0.0-20190326221639-3ad05305c9b0/internal/span/token.go:70 +0x5cd
golang.org/x/tools/internal/lsp/source.nodeSpan(0x14acd60, 0xc00026fb90, 0xc00018c0c0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
	/Users/nayef.ghattas/go/pkg/mod/golang.org/x/tools@v0.0.0-20190326221639-3ad05305c9b0/internal/lsp/source/symbols.go:128 +0xb6
golang.org/x/tools/internal/lsp/source.funcSymbol(0xc00026fb90, 0xc00018c0c0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
	/Users/nayef.ghattas/go/pkg/mod/golang.org/x/tools@v0.0.0-20190326221639-3ad05305c9b0/internal/lsp/source/symbols.go:72 +0xda
golang.org/x/tools/internal/lsp/source.DocumentSymbols(0x14b2fe0, 0xc00009ae40, 0x14b52e0, 0xc0001a80e0, 0xc000096480, 0x3f, 0x14b52e0)
	/Users/nayef.ghattas/go/pkg/mod/golang.org/x/tools@v0.0.0-20190326221639-3ad05305c9b0/internal/lsp/source/symbols.go:43 +0x86a
golang.org/x/tools/internal/lsp.(*server).DocumentSymbol(0xc00009ad00, 0x14b2fe0, 0xc00009ae40, 0xc000086d30, 0xc000086d30, 0x0, 0x0, 0x102cd11, 0x1440b80)
	/Users/nayef.ghattas/go/pkg/mod/golang.org/x/tools@v0.0.0-20190326221639-3ad05305c9b0/internal/lsp/server.go:452 +0xe8
golang.org/x/tools/internal/lsp/protocol.serverHandler.func1(0x14b2fe0, 0xc00009ae40, 0xc0001643f0, 0xc000090ec0)
	/Users/nayef.ghattas/go/pkg/mod/golang.org/x/tools@v0.0.0-20190326221639-3ad05305c9b0/internal/lsp/protocol/server.go:274 +0x399f
golang.org/x/tools/internal/jsonrpc2.(*Conn).run(0xc0001643f0, 0x14b3020, 0xc000098008, 0xc000000000, 0x0)
	/Users/nayef.ghattas/go/pkg/mod/golang.org/x/tools@v0.0.0-20190326221639-3ad05305c9b0/internal/jsonrpc2/jsonrpc2.go:327 +0x67b
golang.org/x/tools/internal/jsonrpc2.NewConn.func4(0xc0001643f0, 0x14b3020, 0xc000098008)
	/Users/nayef.ghattas/go/pkg/mod/golang.org/x/tools@v0.0.0-20190326221639-3ad05305c9b0/internal/jsonrpc2/jsonrpc2.go:107 +0x3f
created by golang.org/x/tools/internal/jsonrpc2.NewConn
	/Users/nayef.ghattas/go/pkg/mod/golang.org/x/tools@v0.0.0-20190326221639-3ad05305c9b0/internal/jsonrpc2/jsonrpc2.go:106 +0x18d

@gopherbot
Copy link

Change https://golang.org/cl/169440 mentions this issue: internal/span: return error when on spans with invalid starts

@stamblerre
Copy link
Contributor

Yeah, I've noticed that as well, thank you for bringing it up. Sent out a CL which will hopefully fix it.

@golang golang locked and limited conversation to collaborators Mar 26, 2020
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.
Projects
None yet
Development

No branches or pull requests

5 participants