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: bug.Reportf("no metadata for %s") when hovering over package name of broken import #60592

Closed
adonovan opened this issue Jun 4, 2023 · 2 comments
Assignees
Labels
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

@adonovan
Copy link
Member

adonovan commented Jun 4, 2023

While snooping around in the file cache I noticed a crash dump from a non-test binary: the v0.12.0 release binary, in fact. The report is

{
   "AtTime" : "2023-06-01T16:57:35.701388-04:00",
   "Description" : "no metadata for file:///Users/adonovan/w/xtools/aaa/aaa.go",
   "File" : "/Users/adonovan/go/pkg/mod/golang.org/x/tools/gopls@v0.12.0/internal/lsp/source/hover.go",
   "Key" : "/Users/adonovan/go/pkg/mod/golang.org/x/tools/gopls@v0.12.0/internal/lsp/source/hover.go:272",
   "Line" : 272,
   ...
}

The stack (which I've omitted) provides no useful information that isn't deducible from the line number above. Here's the source:

		// For package names, we simply link to their imported package.
		if pkgName, ok := obj.(*types.PkgName); ok {
			linkName = pkgName.Name()
			linkPath = pkgName.Imported().Path()
			impID := linkMeta.DepsByPkgPath[PackagePath(pkgName.Imported().Path())]
			linkMeta = snapshot.Metadata(impID)
			if linkMeta == nil {
				return protocol.Range{}, nil, bug.Errorf("no metadata for %s", declPGF.URI) // <--- here
			}
		} else {

Sadly I no longer have (or remember) the contents of aaa.go, a scratch file I used for a quick experiment.

Also: although gopls stats decodes bug reports from the same executable, it's surprisingly laborious to enumerate and decode all the bug reports from all versions $GOPLSCACHE/gopls/*/*/*-bug, since these (binary) files contain the (hex) names of other files: a sort of binary symlink. (I ended up just grepping for the shibboleth "AtTime".) It would be nice if there was a simple command to print all bug reports in the GOPLSCACHE, including those from other gopls binaries (a best-effort decoding, of course, since the format may evolve).

@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 Jun 4, 2023
@gopherbot gopherbot added this to the Unreleased milestone Jun 4, 2023
@findleyr findleyr modified the milestones: Unreleased, gopls/v0.13.0 Jun 15, 2023
@adonovan
Copy link
Member Author

I was able to reproduce this at master (87ad891) by hovering over the foo in foo.Print in this program:

package main

import foo "a"

func _() {
	foo.Print()
}

@adonovan adonovan changed the title x/tools/gopls: bug.Reportf("no metadata for %s") reached in hover.go x/tools/gopls: bug.Reportf("no metadata for %s") when hovering over package name of broken import Jun 28, 2023
@findleyr findleyr modified the milestones: gopls/v0.14.0, gopls/v0.14.1 Oct 9, 2023
@findleyr findleyr modified the milestones: gopls/v0.14.2, gopls/v0.15.0 Nov 14, 2023
@adonovan adonovan self-assigned this Jan 23, 2024
@gopherbot
Copy link

Change https://go.dev/cl/557715 mentions this issue: gopls/internal/test/integration: add regtest for hover crash

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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

3 participants