Skip to content

cmd/go, x/tools/gopls: clarify error messages about std modules (which have no '.') #65301

Open
golang/tools
#471
@meling

Description

@meling

Go version

go version devel go1.22-33d4a51 darwin/arm64

Output of go env in your module/workspace:

Not relevant. It isn't a bug per se, but a request for better error messages.

What did you do?

go.mod:

module notstd

go 1.22

server/server.go:

package main

import "notstd/proto"

func Insert(req *proto.InsertRequest) (*proto.InsertResponse, error) {
	return &proto.InsertResponse{Success: true}, nil
}

There are no Go files in the proto folder (yet):

├── go.mod
├── proto
│   └── kv.proto
└── server
    └── server.go

What did you see happen?

$ go run ./server/
server/server.go:4:2: package notstd/proto is not in std (/Users/meling/sdk/gotip/src/notstd/proto)
$ gopls check server/server.go
/Users/meling/tmp/notstd/server/server.go:4:2-16: could not import notstd/proto (no required module provides package "notstd/proto")

When opening the quick fix suggestions in VSCode, gopls or the Go extension suggests to go get package notstd/proto, which is nonsensical.

What did you expect to see?

I would expect both the compiler and gopls to report that there are no Go files in the proto folder within the same module, since the import is explicitly trying to import its own package.

With the simple example it might seem trivial to figure out that you've forgotten to compile the proto file to populate the proto package. But in larger projects it may be easy to forget, and students don't necessarily understand what the problem is, if they are expected to compile the proto file themselves. Moreover, the error messages are not helpful in this case.

Edit: Added the kv.proto file to match the actual use case that triggered this and simplified the what to expect description.

Metadata

Metadata

Assignees

No one assigned

    Labels

    goplsIssues related to the Go language server, gopls.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions