Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
cmd/go: 'go mod edit' should validate the provided version format #27060
Before editing the contents, the newly added values need validation.
In the following commands sequence, the error in the first go mod edit command is not reported until the next go mod command.
$ go mod init example.com/mod go: creating new go.mod: module example.com/mod $ go mod edit -require golang.org/x/text/cases@latest $ go mod edit -require golang.org/x/text/date@latest go: errors parsing go.mod: /scratch/mod/go.mod:3: invalid module version "latest": version must be of the form v1.2.3
Sorry, but working as intended and documented. Edit is for editing, primarily to be invoked by tools. Most people should not run edit directly. Instead, if you want to add a requirement with all the semantic extras, use 'go get'.
'go help mod edit' explains:
referenced this issue
Aug 29, 2018
"go get" currently involves checking module lists over network. If change to the module is not committed upstream yet (e.g., in the middle of local development), we need a way to configure the require+replace rules and 'go get' doesn't support the use case. I observed multiple users (including me) suggested hand-edit of go.mod files with fake versions as a workaround. That's not ideal and we need a reliable tool (if go mod edit -require is not the recommended path).