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

Comments

Projects
None yet
4 participants
@hyangah
Copy link
Contributor

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

This comment has been minimized.

Copy link
Member

commented Aug 17, 2018

@rsc

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link
Contributor Author

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

This comment has been minimized.

Copy link
Member

commented Sep 7, 2018

I think the loop here is closed by #26241

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.