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

cmd/doc: Panic when showing unexported symbols on pkg with invalid go file #17788

keegancsmith opened this issue Nov 4, 2016 · 3 comments
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.


Copy link

Please answer these questions before submitting your issue. Thanks!

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

go version go1.7.3 darwin/amd64

What operating system and processor architecture are you using (go env)?


What did you do?

$ go get -d
$ go doc -u
panic: runtime error: index out of range

goroutine 1 [running]:
panic(0x177620, 0xc4200101a0)
        /usr/local/Cellar/go/1.7.3/libexec/src/runtime/panic.go:500 +0x1a1
go/doc.(*reader).readFunc(0xc420041c60, 0xc420078e70)
        /usr/local/Cellar/go/1.7.3/libexec/src/go/doc/reader.go:365 +0x3af
go/doc.(*reader).readFile(0xc420041c60, 0xc4200a4a00)
        /usr/local/Cellar/go/1.7.3/libexec/src/go/doc/reader.go:519 +0x5fb
go/doc.(*reader).readPackage(0xc420041c60, 0xc420078ff0, 0x1)
        /usr/local/Cellar/go/1.7.3/libexec/src/go/doc/reader.go:552 +0x35a
go/doc.New(0xc420078ff0, 0x7fff5fbff320, 0x4d, 0x1, 0xc42007b8e8)
        /usr/local/Cellar/go/1.7.3/libexec/src/go/doc/doc.go:96 +0x7f
main.parsePackage(0x2504a0, 0xc420094008, 0xc42007d880, 0x7fff5fbff320, 0x4d, 0x0)
        /usr/local/Cellar/go/1.7.3/libexec/src/cmd/doc/pkg.go:140 +0x183, 0xc420094008, 0xc4200742a0, 0xc420078190, 0x2, 0x2, 0x0, 0x0)
        /usr/local/Cellar/go/1.7.3/libexec/src/cmd/doc/main.go:97 +0x2e9
        /usr/local/Cellar/go/1.7.3/libexec/src/cmd/doc/main.go:72 +0xbc
exit status 2

What did you expect to see?

No panic

What did you see instead?

A panic! The go file it is parsing is not valid go, but I don't expect to see a panic.

More context:

This only happens if you pass in -u. We noticed this error in production at Sourcegraph due to using doc.New with the Mode set to doc.AllDecls (see ). Production is a linux environment. I could reproduce it with the go doc command, so reported it as such.

Copy link
Contributor Author

keegancsmith commented Nov 4, 2016

Here is a minimal example to reproduce:

package issue17788

func ( /* receiver type */ ) f0() {

placing this at src/go/doc/testdata/issue17788.go will get go test to panic.

Copy link

CL mentions this issue.

keegancsmith added a commit to sourcegraph/go-langserver that referenced this issue Nov 4, 2016
Currently we are getting panics sometimes running workspace/symbols due to a bug
in `go/doc`. golang/go#17788

This change prevents panics in our pkg collector goroutines taking the whole
server down. In the future we may want to have a better approach so we don't
accidently ignore panics, but for now this lets us move forward.
@quentinmit quentinmit added the NeedsFix The path to resolution is known, but the work has not been done. label Nov 4, 2016
@quentinmit quentinmit added this to the Go1.8Maybe milestone Nov 4, 2016
Copy link
Contributor Author

@quentinmit FYI I added which fixes the panic

@golang golang locked and limited conversation to collaborators Nov 11, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
None yet

No branches or pull requests

3 participants