Skip to content

x/tools/gopls: recovered panic in RenderPackageDoc #66449

Closed
@adonovan

Description

@adonovan

Steps:

  1. Clone repo and visit this file: https://codeberg.org/pfad.fr/vanitydoc/src/branch/main/example/nested/chan.go
  2. Source Actions > View Package Documentation...

Observe panic (recovered by net/http) below.

The offending line is:

buf.WriteString(escape(string(file.Src[start:end])))
panic serving 127.0.0.1:58457: runtime error: slice bounds out of range [:-1]
goroutine 4715 [running]:
net/http.(*conn).serve.func1()
	/Users/adonovan/w/goroot/src/net/http/server.go:1898 +0xb0
panic({0x105945a00?, 0x14007088978?})
	/Users/adonovan/w/goroot/src/runtime/panic.go:759 +0x124
golang.org/x/tools/gopls/internal/golang.RenderPackageDoc.func4.2(0x0)
	/Users/adonovan/w/xtools/gopls/internal/golang/pkgdoc.go:187 +0xfc
golang.org/x/tools/gopls/internal/golang.RenderPackageDoc.func4.3({0x1059aa120?, 0x106001dc0})
	/Users/adonovan/w/xtools/gopls/internal/golang/pkgdoc.go:193 +0x128
go/ast.inspector.Visit(0x1400191b350, {0x1059aa120?, 0x106001dc0?})
	/Users/adonovan/w/goroot/src/go/ast/walk.go:386 +0x38
go/ast.Walk({0x1059a6dc0?, 0x1400191b350?}, {0x1059aa120, 0x106001dc0})
	/Users/adonovan/w/goroot/src/go/ast/walk.go:51 +0x44
go/ast.walkIdentList(...)
	/Users/adonovan/w/goroot/src/go/ast/walk.go:20
go/ast.Walk({0x1059a6dc0?, 0x1400191b350?}, {0x1059aa988, 0x1400210cb90})
	/Users/adonovan/w/goroot/src/go/ast/walk.go:314 +0x661
go/ast.Walk({0x1059a6dc0?, 0x1400191b350?}, {0x1059aa618, 0x140018d5b40})
	/Users/adonovan/w/goroot/src/go/ast/walk.go:344 +0x20e8
go/ast.Inspect(...)
	/Users/adonovan/w/goroot/src/go/ast/walk.go:397
golang.org/x/tools/gopls/internal/golang.RenderPackageDoc.func4({0x1059aa618, 0x140018d5b40})
	/Users/adonovan/w/xtools/gopls/internal/golang/pkgdoc.go:190 +0x1e5
golang.org/x/tools/gopls/internal/golang.RenderPackageDoc.func6({0x140023b2780, 0x16, 0x105530eb5?})
	/Users/adonovan/w/xtools/gopls/internal/golang/pkgdoc.go:300 +0x5c
golang.org/x/tools/gopls/internal/golang.RenderPackageDoc(0x14006893c80, 0x14002949860, 0x140080432f0)
	/Users/adonovan/w/xtools/gopls/internal/golang/pkgdoc.go:316 +0x958

@oliverpool

Activity

self-assigned this
on Mar 21, 2024
added
ToolsThis label describes issues relating to any tools in the x/tools repository.
goplsIssues related to the Go language server, gopls.
on Mar 21, 2024
added this to the Unreleased milestone on Mar 21, 2024
adonovan

adonovan commented on Mar 21, 2024

@adonovan
MemberAuthor

This appears to be a consequence of doc.New mutating the AST, even though it is not permitted to do so in PreserveAST mode. The NamePos of the ok Ident becomes zero. Still investigating...

gopherbot

gopherbot commented on Mar 21, 2024

@gopherbot
Contributor

Change https://go.dev/cl/573575 mentions this issue: gopls/internal/golang: work around bug in go/doc

added a commit that references this issue on Mar 29, 2024
509ed1c
locked and limited conversation to collaborators on Mar 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

FrozenDueToAgeToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.

Type

No type

Projects

No projects

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @adonovan@gopherbot

      Issue actions

        x/tools/gopls: recovered panic in RenderPackageDoc · Issue #66449 · golang/go