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/go: confusing error message when flags come before package paths #56310

Open
josharian opened this issue Oct 18, 2022 · 4 comments
Open

cmd/go: confusing error message when flags come before package paths #56310

josharian opened this issue Oct 18, 2022 · 4 comments
Labels
GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Unfortunate
Milestone

Comments

@josharian
Copy link
Contributor

-- go.mod --
module m

go 1.19
-- x/t_test.go --
package x

// some test code that has a -foo flag

(Warning: hand-written, untested txtar.)

$ go test ./x -foo
<OK>
$ go test -foo ./x
no Go files in /current/pwd

This is a confusing error message. I think(?) the Go tool has interpreted -foo as a package path, but the error message doesn't reflect that. It's true that there are no Go files in the root, but that's not the problem.

Maybe the Go command could make these two equivalent. But even if it can't, a more useful error message would be welcome.

@dr2chase dr2chase added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Oct 19, 2022
@dr2chase
Copy link
Contributor

@bcmills @rsc
I am not sure what the best approach here might be, it seems like it might involve some pattern-matching in the error path.

@bcmills
Copy link
Contributor

bcmills commented Oct 20, 2022

I think(?) the Go tool has interpreted -foo as a package path, but the error message doesn't reflect that.

Nope: it has interpreted -foo ./x as the flag -foo with argument ./x, leaving an implicit package path of “.”.

I agree that the diagnostic could perhaps be improved, though.

@bcmills bcmills added this to the Backlog milestone Oct 20, 2022
@josharian
Copy link
Contributor Author

Oof.

Why should cmd/go assume that -foo takes an arg, as opposed to being a bool flag?

@bcmills
Copy link
Contributor

bcmills commented Oct 20, 2022

It doesn't know, so it has to make a conservative guess. (FWIW, the situation was even worse before https://go.dev/cl/211358 and https://go.dev/cl/248618. 😅)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Unfortunate
Projects
None yet
Development

No branches or pull requests

3 participants