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: 'go mod edit' should validate the provided version format #27060

Closed
hyangah opened this issue Aug 17, 2018 · 4 comments
Closed

cmd/go: 'go mod edit' should validate the provided version format #27060

hyangah opened this issue Aug 17, 2018 · 4 comments
Labels
FrozenDueToAge modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@hyangah
Copy link
Contributor

hyangah commented Aug 17, 2018

Before editing the contents, the newly added values need validation.
Currently the error checking is done only when parsing the existing go.mod contents.

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
@andybons andybons added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. modules labels Aug 17, 2018
@andybons andybons added this to the Unplanned milestone Aug 17, 2018
@andybons
Copy link
Member

@rsc @bcmills

@rsc
Copy link
Contributor

rsc commented Aug 18, 2018

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:

The -require=path@version and -droprequire=path flags ....
These flags are mainly for tools that understand the module graph.
Users should prefer 'go get path@version' or 'go get path@none',
which make other go.mod adjustments as needed to satisfy
constraints imposed by other modules.

@hyangah
Copy link
Contributor Author

hyangah commented Aug 30, 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).

@myitcv
Copy link
Member

myitcv commented Sep 7, 2018

I think the loop here is closed by #26241

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge modules 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

5 participants