Go version
go version go1.23.1 darwin/arm64
Output of go env -changed
in your module/workspace
GOPROXY='http://127.0.0.1'
What did you do?
https://pkg.go.dev/cmd/go#hdr-Download_modules_to_local_cache says:
The -json flag causes download to print a sequence of JSON objects to standard output, describing each downloaded module (or failure), corresponding to this Go struct:
type Module struct { ... }
It seems that doesn't always happen for some networking errors observed in the Go build system (build 8736907273916323825 being one example). Consider a minimal set of steps which seems to reproduce the problem:
$ export GOPROXY=http://127.0.0.1 # simulate an error downloading modules
$ cd $(mktemp -d)
$ printf 'module test\nrequire example.com v0.0.0\n' > go.mod
$ go mod download -json
What did you see happen?
No JSON is printed to stdout:
$ go mod download -json 2>/dev/null
$
What did you expect to see?
JSON is printed to stdout, describing the error:
$ go mod download -json 2>/dev/null
{
"Path": "example.com",
"Version": "v0.0.0",
"Error": "Get \"http://127.0.0.1/example.com/@v/v0.0.0.mod\": dial tcp 127.0.0.1:80: connect: connection refused"
}
$
CC @matloob, @samthanawalla.
Comment From: gabyhelp
Related Issues and Documentation
- cmd/go: document that go mod download -json uses exit code 1 when at least one JSON entry contains non-zero Error #35380
- Proposal: cmd/go: return parseable errors for mod download #30725 (closed)
- cmd/go: go module fetching gives unexpected stderr output #36297 (closed)
- cmd/go: make go mod download -json return the exit status 0 in case of errors #36833 (closed)
- go mod download does not fallback to http if https is not available #36394 (closed)
- cmd/go: go mod download -json does not output json when sumdb fails #34485 (closed)
- cmd/go: go test -json has non-JSON printed to stdout when build fails #35169 (closed)
- cmd/go: treat most errors as fatal when resolving a package with a proxy #31730
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)