-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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/go, x/tools/gopls: clarify error messages about std modules (which have no '.') #65301
Comments
I think cmd/go may be working as intended, we've previously stated that all names without a dot in the first component are considered reserved for the standard library. |
It is nonsensical to suggest |
Perhaps when the go command fails it could additionally report whether the go.mod file contains "module foo" where foo contains no '.' and is not "std"? @bcmills @matloob Also, perhaps gopls could have a checker to report module declarations of that form so that one learns the '.' rule as soon as you make the mistake. (Update: @findleyr tells me that there are unfortunately quite a few modules out there that use such names: they work fine as a main module, even though they aren't gettable. Perhaps a hint augmenting the gopls error message would be better.) |
That reminds me, I need to clean up https://go.dev/cl/359594 and get it merged. 😩 |
Let me add a little more context for our use case... I really like that I can do things like the following for our courses, where module dat520 In fact, the whole point is that the main repository should not be go gettable as it is private and contains more code than we share with students. We copy part of the main repository to another per-year repository, e.g., I really hope that we can keep using our current approach, and that the "module names without dots are reserved" idea will never be enforced. I would much rather have to deal with a less-than-ideal error message (it is easy to detect now that we know about it), than to loose the ability to use a module name like |
Thanks for the context. I agree, this usage seems quite reasonable and in any case we can't disallow previously legal behavior. As I noted in my post script, perhaps the best we can do is add an additional hint when the go command exits with certain errors. |
I wonder why this program does not reproduce the problem.
|
If you
Seems to happen only when there are no Go files in the folder. I came across this problem when some of my students forgot to generate a Not sure, but maybe this fact could be used to pick another error message for this case, e.g.: |
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
:server/server.go
:There are no Go files in the
proto
folder (yet):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 togo 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.The text was updated successfully, but these errors were encountered: