Skip to content

Proposal: cmd/go: return parseable errors for mod download #30725

Closed
@marwan-at-work

Description

@marwan-at-work

Summary

Per @rsc 's comment, all proxies must use go mod download to ensure checksums are consistent amongst each other.

Therefore, Proxies that try to download modules through the go command should be able to understand errors in a programmatic way without having to parse text. Such errors can be:

  1. Repository not found
  2. The requested version does not exist
  3. Authentication failure for private modules
  4. Incorrect module path (does not begin with host name)

go mod download takes a -json flag which includes an Error string inside of it. I propose that we include an ErrorCode or at the very least be confident that the Error strings will be locked and not changed without notice.

Furthermore, some of the messages in the Error field are inaccurate, see below for details.

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

$ go version
go version go1.12 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What did you do?

  1. go mod download -json bad/path@latest
  2. go mod download -json bad/[email protected]
  3. go mod download -json github.com/gomods/moduledoesnotexist@latest
  4. go mod download -json github.com/gomods/[email protected]

What did you expect to see?

  1. Reliable code or message to say it's a bad module path
  2. Reliable code or message to say it's a bad module path.
  3. Reliable code or message to say that the module does not exist.
  4. Reliable code or message to say that the module does not exist.

What did you see instead?

  1. Incorrect error message: it should prioritize saying that the module path is incorrect rather than that the version invalid. In fact, latest is not invalid.
{
	"Path": "github.com/gomods/moduledoesnotexist",
	"Version": "latest",
	"Error": "invalid version \"latest\""
}
  1. Correct error message, comparing against no.1 above, but it might be helpful to lock the message or introduce an error code.
{
	"Path": "bad/path",
	"Version": "v0.9.0",
	"Error": "unrecognized import path \"bad/path\" (import path does not begin with hostname)"
}
  1. Incorrect error message same as no.1
{
	"Path": "github.com/gomods/moduledoesnotexist",
	"Version": "latest",
	"Error": "invalid version \"latest\""
}
  1. Inaccurate error message: it should tell us that the Repository is not found, instead of "invalid revision"
{
	"Path": "github.com/gomods/moduledoesnotexist",
	"Version": "v0.9.0",
	"Error": "unknown revision v0.9.0"
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions