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 download -json` should output valid json #33648

Closed
jakecollins opened this issue Aug 14, 2019 · 3 comments
Closed

cmd/go: `go mod download -json` should output valid json #33648

jakecollins opened this issue Aug 14, 2019 · 3 comments

Comments

@jakecollins
Copy link

@jakecollins jakecollins commented Aug 14, 2019

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

$ go version
go version go1.12.8 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/jakcollins/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/jakcollins/dev/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/jakcollins/dev/github.expedia.biz/Brand-Expedia/aws_key_gen/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/s4/655pl1x12pjc0c05f43ptjx94hrmpt/T/go-build867894321=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

git clone git@github.com:golang/tools.git
cd tools
go mod download -json

What did you expect to see?

Well formed json output, please click to expand example below.

go mod download -json Output
$ go mod download -json
[
	{
		"Path": "golang.org/x/crypto",
		"Version": "v0.0.0-20190308221718-c2843e01d9a2",
		"Info": "/Users/jakcollins/dev/go/pkg/mod/cache/download/golang.org/x/crypto/@v/v0.0.0-20190308221718-c2843e01d9a2.info",
		"GoMod": "/Users/jakcollins/dev/go/pkg/mod/cache/download/golang.org/x/crypto/@v/v0.0.0-20190308221718-c2843e01d9a2.mod",
		"Zip": "/Users/jakcollins/dev/go/pkg/mod/cache/download/golang.org/x/crypto/@v/v0.0.0-20190308221718-c2843e01d9a2.zip",
		"Dir": "/Users/jakcollins/dev/go/pkg/mod/golang.org/x/crypto@v0.0.0-20190308221718-c2843e01d9a2",
		"Sum": "h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M=",
		"GoModSum": "h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w="
	},
	{
		"Path": "golang.org/x/net",
		"Version": "v0.0.0-20190620200207-3b0461eec859",
		"Info": "/Users/jakcollins/dev/go/pkg/mod/cache/download/golang.org/x/net/@v/v0.0.0-20190620200207-3b0461eec859.info",
		"GoMod": "/Users/jakcollins/dev/go/pkg/mod/cache/download/golang.org/x/net/@v/v0.0.0-20190620200207-3b0461eec859.mod",
		"Zip": "/Users/jakcollins/dev/go/pkg/mod/cache/download/golang.org/x/net/@v/v0.0.0-20190620200207-3b0461eec859.zip",
		"Dir": "/Users/jakcollins/dev/go/pkg/mod/golang.org/x/net@v0.0.0-20190620200207-3b0461eec859",
		"Sum": "h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI=",
		"GoModSum": "h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s="
	},
	{
		"Path": "golang.org/x/sync",
		"Version": "v0.0.0-20190423024810-112230192c58",
		"Info": "/Users/jakcollins/dev/go/pkg/mod/cache/download/golang.org/x/sync/@v/v0.0.0-20190423024810-112230192c58.info",
		"GoMod": "/Users/jakcollins/dev/go/pkg/mod/cache/download/golang.org/x/sync/@v/v0.0.0-20190423024810-112230192c58.mod",
		"Zip": "/Users/jakcollins/dev/go/pkg/mod/cache/download/golang.org/x/sync/@v/v0.0.0-20190423024810-112230192c58.zip",
		"Dir": "/Users/jakcollins/dev/go/pkg/mod/golang.org/x/sync@v0.0.0-20190423024810-112230192c58",
		"Sum": "h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=",
		"GoModSum": "h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM="
	},
	{
		"Path": "golang.org/x/sys",
		"Version": "v0.0.0-20190215142949-d0b11bdaac8a",
		"Info": "/Users/jakcollins/dev/go/pkg/mod/cache/download/golang.org/x/sys/@v/v0.0.0-20190215142949-d0b11bdaac8a.info",
		"GoMod": "/Users/jakcollins/dev/go/pkg/mod/cache/download/golang.org/x/sys/@v/v0.0.0-20190215142949-d0b11bdaac8a.mod",
		"Zip": "/Users/jakcollins/dev/go/pkg/mod/cache/download/golang.org/x/sys/@v/v0.0.0-20190215142949-d0b11bdaac8a.zip",
		"Dir": "/Users/jakcollins/dev/go/pkg/mod/golang.org/x/sys@v0.0.0-20190215142949-d0b11bdaac8a",
		"Sum": "h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=",
		"GoModSum": "h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY="
	},
	{
		"Path": "golang.org/x/text",
		"Version": "v0.3.0",
		"Info": "/Users/jakcollins/dev/go/pkg/mod/cache/download/golang.org/x/text/@v/v0.3.0.info",
		"GoMod": "/Users/jakcollins/dev/go/pkg/mod/cache/download/golang.org/x/text/@v/v0.3.0.mod",
		"Zip": "/Users/jakcollins/dev/go/pkg/mod/cache/download/golang.org/x/text/@v/v0.3.0.zip",
		"Dir": "/Users/jakcollins/dev/go/pkg/mod/golang.org/x/text@v0.3.0",
		"Sum": "h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=",
		"GoModSum": "h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ="
	},
	{
		"Path": "golang.org/x/xerrors",
		"Version": "v0.0.0-20190717185122-a985d3407aa7",
		"Info": "/Users/jakcollins/dev/go/pkg/mod/cache/download/golang.org/x/xerrors/@v/v0.0.0-20190717185122-a985d3407aa7.info",
		"GoMod": "/Users/jakcollins/dev/go/pkg/mod/cache/download/golang.org/x/xerrors/@v/v0.0.0-20190717185122-a985d3407aa7.mod",
		"Zip": "/Users/jakcollins/dev/go/pkg/mod/cache/download/golang.org/x/xerrors/@v/v0.0.0-20190717185122-a985d3407aa7.zip",
		"Dir": "/Users/jakcollins/dev/go/pkg/mod/golang.org/x/xerrors@v0.0.0-20190717185122-a985d3407aa7",
		"Sum": "h1:9zdDQZ7Thm29KFXgAX/+yaf3eVbP7djjWp/dXAppNCc=",
		"GoModSum": "h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0="
	}
]

What did you see instead?

The output was not well formed json. It contained a 'go: finding ...' message and the list of module objects was not wrapped in a comma delimited json list. Please click to expand example below.

go mod download -json Output
$ go mod download -json
go: finding golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7
{
	"Path": "golang.org/x/crypto",
	"Version": "v0.0.0-20190308221718-c2843e01d9a2",
	"Info": "/Users/jakcollins/dev/go/pkg/mod/cache/download/golang.org/x/crypto/@v/v0.0.0-20190308221718-c2843e01d9a2.info",
	"GoMod": "/Users/jakcollins/dev/go/pkg/mod/cache/download/golang.org/x/crypto/@v/v0.0.0-20190308221718-c2843e01d9a2.mod",
	"Zip": "/Users/jakcollins/dev/go/pkg/mod/cache/download/golang.org/x/crypto/@v/v0.0.0-20190308221718-c2843e01d9a2.zip",
	"Dir": "/Users/jakcollins/dev/go/pkg/mod/golang.org/x/crypto@v0.0.0-20190308221718-c2843e01d9a2",
	"Sum": "h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M=",
	"GoModSum": "h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w="
}
{
	"Path": "golang.org/x/net",
	"Version": "v0.0.0-20190620200207-3b0461eec859",
	"Info": "/Users/jakcollins/dev/go/pkg/mod/cache/download/golang.org/x/net/@v/v0.0.0-20190620200207-3b0461eec859.info",
	"GoMod": "/Users/jakcollins/dev/go/pkg/mod/cache/download/golang.org/x/net/@v/v0.0.0-20190620200207-3b0461eec859.mod",
	"Zip": "/Users/jakcollins/dev/go/pkg/mod/cache/download/golang.org/x/net/@v/v0.0.0-20190620200207-3b0461eec859.zip",
	"Dir": "/Users/jakcollins/dev/go/pkg/mod/golang.org/x/net@v0.0.0-20190620200207-3b0461eec859",
	"Sum": "h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI=",
	"GoModSum": "h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s="
}
{
	"Path": "golang.org/x/sync",
	"Version": "v0.0.0-20190423024810-112230192c58",
	"Info": "/Users/jakcollins/dev/go/pkg/mod/cache/download/golang.org/x/sync/@v/v0.0.0-20190423024810-112230192c58.info",
	"GoMod": "/Users/jakcollins/dev/go/pkg/mod/cache/download/golang.org/x/sync/@v/v0.0.0-20190423024810-112230192c58.mod",
	"Zip": "/Users/jakcollins/dev/go/pkg/mod/cache/download/golang.org/x/sync/@v/v0.0.0-20190423024810-112230192c58.zip",
	"Dir": "/Users/jakcollins/dev/go/pkg/mod/golang.org/x/sync@v0.0.0-20190423024810-112230192c58",
	"Sum": "h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=",
	"GoModSum": "h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM="
}
{
	"Path": "golang.org/x/sys",
	"Version": "v0.0.0-20190215142949-d0b11bdaac8a",
	"Info": "/Users/jakcollins/dev/go/pkg/mod/cache/download/golang.org/x/sys/@v/v0.0.0-20190215142949-d0b11bdaac8a.info",
	"GoMod": "/Users/jakcollins/dev/go/pkg/mod/cache/download/golang.org/x/sys/@v/v0.0.0-20190215142949-d0b11bdaac8a.mod",
	"Zip": "/Users/jakcollins/dev/go/pkg/mod/cache/download/golang.org/x/sys/@v/v0.0.0-20190215142949-d0b11bdaac8a.zip",
	"Dir": "/Users/jakcollins/dev/go/pkg/mod/golang.org/x/sys@v0.0.0-20190215142949-d0b11bdaac8a",
	"Sum": "h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=",
	"GoModSum": "h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY="
}
{
	"Path": "golang.org/x/text",
	"Version": "v0.3.0",
	"Info": "/Users/jakcollins/dev/go/pkg/mod/cache/download/golang.org/x/text/@v/v0.3.0.info",
	"GoMod": "/Users/jakcollins/dev/go/pkg/mod/cache/download/golang.org/x/text/@v/v0.3.0.mod",
	"Zip": "/Users/jakcollins/dev/go/pkg/mod/cache/download/golang.org/x/text/@v/v0.3.0.zip",
	"Dir": "/Users/jakcollins/dev/go/pkg/mod/golang.org/x/text@v0.3.0",
	"Sum": "h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=",
	"GoModSum": "h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ="
}
{
	"Path": "golang.org/x/xerrors",
	"Version": "v0.0.0-20190717185122-a985d3407aa7",
	"Info": "/Users/jakcollins/dev/go/pkg/mod/cache/download/golang.org/x/xerrors/@v/v0.0.0-20190717185122-a985d3407aa7.info",
	"GoMod": "/Users/jakcollins/dev/go/pkg/mod/cache/download/golang.org/x/xerrors/@v/v0.0.0-20190717185122-a985d3407aa7.mod",
	"Zip": "/Users/jakcollins/dev/go/pkg/mod/cache/download/golang.org/x/xerrors/@v/v0.0.0-20190717185122-a985d3407aa7.zip",
	"Dir": "/Users/jakcollins/dev/go/pkg/mod/golang.org/x/xerrors@v0.0.0-20190717185122-a985d3407aa7",
	"Sum": "h1:9zdDQZ7Thm29KFXgAX/+yaf3eVbP7djjWp/dXAppNCc=",
	"GoModSum": "h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0="
}
@DisposaBoy

This comment has been minimized.

Copy link

@DisposaBoy DisposaBoy commented Aug 14, 2019

The output was not well formed json. It contained a 'go: finding ...' message

AFAICT, that output is on stderr so it's fine IMO.

and the list of module objects was not wrapped in a comma delimited json list.

It's a stream of JSON objects? which is in line with JSON output from other sub-commands as well as being idiomatic(tm) and common which also makes it fine IMO.

@jayconrod

This comment has been minimized.

Copy link
Contributor

@jayconrod jayconrod commented Aug 14, 2019

Agree with @DisposaBoy's comment. This is working as intended.

Status messages are printed on stderr so the JSON output can be piped to tools and files separately. Errors are included in the JSON objects (in the Error field).

Printing a stream of JSON objects instead of a single list value is also expected. go list does this as well. Tools like jq work well with this format.

@jayconrod jayconrod closed this Aug 14, 2019
@jakecollins

This comment has been minimized.

Copy link
Author

@jakecollins jakecollins commented Aug 15, 2019

Okay, makes sense. Thank you for the explanation.

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