sourcegraph / go-langserver

Go language server to add Go support to editors and other tools that use the Language Server Protocol (LSP)
https://sourcegraph.com
MIT License
1.17k stars 89 forks source link

Adding an error check in handleHoverGodef #340

Closed abhi closed 5 years ago

abhi commented 5 years ago

This commit adds an error check to avoid crash while accessing the result of typecheck when there is an error generated. Encountered a panic during hover. I don't have a way to reproduce it consistently. However I think this check is necessary. Please let me know otherwise. Posting the panic st.

panic serving textDocument/hover: runtime error: invalid memory address or nil pointer dereference
goroutine 75264 [running]:
third-party-source/go/src/github.com/sourcegraph/go-langserver/langserver/util.Panicf(0xa918c0, 0x10cfe90, 0xb4be8f, 0x2, 0xc0270f1248, 0x1, 0x1, 0xc0270f1258, 0x45b656)
    third-party-source/go/src/github.com/sourcegraph/go-langserver/langserver/util/util.go:133 +0x93
third-party-source/go/src/github.com/sourcegraph/go-langserver/langserver.(*LangHandler).Handle.func1(0xc0327aa320, 0xc0270f1b78)
    third-party-source/go/src/github.com/sourcegraph/go-langserver/langserver/handler.go:164 +0xc4
panic(0xa918c0, 0x10cfe90)
something.../.../.../tools/go/src/runtime/panic.go:513 +0x1b9
third-party-source/go/src/github.com/sourcegraph/go-langserver/langserver.(*LangHandler).handleHoverGodef(0xc0000e1b00, 0xc42c20, 0xc032776240, 0xc41c20, 0xc000158380, 0xc0327aa320, 0xc018e07a90, 0x49, 0x23, 0x47, ...)
    third-party-source/go/src/github.com/sourcegraph/go-langserver/langserver/hover.go:440 +0xaf6
third-party-source/go/src/github.com/sourcegraph/go-langserver/langserver.(*LangHandler).handleHover(0xc0000e1b00, 0xc42c20, 0xc032776240, 0xc41c20, 0xc000158380, 0xc0327aa320, 0xc018e07a90, 0x49, 0x23, 0x47, ...)
    third-party-source/go/src/github.com/sourcegraph/go-langserver/langserver/hover.go:27 +0x1140
third-party-source/go/src/github.com/sourcegraph/go-langserver/langserver.(*LangHandler).Handle(0xc0000e1b00, 0xc42c20, 0xc032776240, 0xc41c20, 0xc000158380, 0xc0327aa320, 0x0, 0x0, 0x0, 0x0)
    third-party-source/go/src/github.com/sourcegraph/go-langserver/langserver/handler.go:333 +0x1d9e

...............

Signed-off-by: Abhinandan Prativadi aprativadi@fb.com