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: -help and go version are broken when go.mod contains non-standard version #60956

Open
thaJeztah opened this issue Jun 22, 2023 · 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.
Milestone

Comments

@thaJeztah
Copy link
Contributor

What version of Go are you using (go version)?

$ go version
go: downloading go1.22-schrodingers-version-yall (linux/arm64)
go: download go1.22-schrodingers-version-yall for linux/arm64: toolchain not available

Does this issue reproduce with the latest release?

See above

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
go: downloading go1.22-schrodingers-version-yall (linux/arm64)
go: download go1.22-schrodingers-version-yall for linux/arm64: toolchain not available

What did you do?

go mod init foo
sed -i 's/1.21rc2/1.22-schrodingers-version-yall/g' go.mod

go --help
go: downloading go1.22-schrodingers-version-yall (linux/arm64)
go: download go1.22-schrodingers-version-yall for linux/arm64: toolchain not available

go version
go: downloading go1.22-schrodingers-version-yall (linux/arm64)
go: download go1.22-schrodingers-version-yall for linux/arm64: toolchain not available

go --version
go: downloading go1.22-schrodingers-version-yall (linux/arm64)
go: download go1.22-schrodingers-version-yall for linux/arm64: toolchain not available
go mod init foo
sed -i 's/1.21rc2/1.22-schrödingers-version-yall/g' go.mod

go version
go: download go1.22-schrödingers-version-yall: non-semver module version "v0.0.1-go1.22-schrödingers-version-yall.linux-arm64"

go version --help
go: download go1.22-schrödingers-version-yall: non-semver module version "v0.0.1-go1.22-schrödingers-version-yall.linux-arm64"

What did you expect to see?

go --help
Go is a tool for managing Go source code.

Usage:

	go <command> [arguments]
# (etc)

go --version
flag provided but not defined: -version
Go is a tool for managing Go source code.

What did you see instead?

go: downloading go1.22-schrodingers-version-yall (linux/arm64)
go: download go1.22-schrodingers-version-yall for linux/arm64: toolchain not available
@dmitshur dmitshur added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. GoCommand cmd/go labels Jun 22, 2023
@dmitshur dmitshur added this to the Go1.21 milestone Jun 22, 2023
@dmitshur dmitshur changed the title [go1.21 toolchain] --help and go version broken when go.mod contains non-standard version cmd/go: -help and go version are broken when go.mod contains non-standard version Jun 22, 2023
@dmitshur
Copy link
Contributor

CC @rsc, @bcmills, @matloob.

@gopherbot gopherbot modified the milestones: Go1.21, Go1.22 Aug 8, 2023
@thaJeztah
Copy link
Contributor Author

Is it possible to have this fixed in a go1.21 patch release? I see this was moved to go1.22, but this looks like a regression to me.

@dmitshur
Copy link
Contributor

dmitshur commented Aug 21, 2023

This issue still needs to be investigated. It it's determined that the current behavior is buggy, the fix will need to be developed for Go 1.22 first before it can be considered for backport to a minor release of Go 1.21.

To me, it seems that at least the go version aspect is working as intended. See the last two paragraphs of https://go.dev/doc/toolchain#select:

Running go version prints the selected Go toolchain’s version (by running the selected toolchain’s implementation of go version).

Running GOTOOLCHAIN=local go version prints the bundled Go toolchain’s version.

Consider a local toolchain version of "go1.21rc4" and a go.mod file whose "go" line is "go1.21.0". Running go version inside such a module correctly prints "go1.21.0", the version of the toolchain that is selected.

Similarly, it probably makes sense that go --help in the same module prints the output of running go1.21.0's go with "--help" flag, rather than that of go1.21rc4.

@bcmills
Copy link
Contributor

bcmills commented Jan 31, 2024

@thaJeztah, I think it is important that we print an error and return with nonzero exit status in this case, but perhaps the error message we print in case of a failed upgrade could be more helpful?

  • Perhaps it could print the file and line number containing the erroneous go directive.
  • Perhaps it could suggest setting GOTOOLCHAIN=local?

But it's tricky, because additional information risks adding to the confusion instead of clarifying it.

@bcmills bcmills modified the milestones: Go1.23, Backlog Jan 31, 2024
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.
Projects
None yet
Development

No branches or pull requests

4 participants