Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
cmd/go: go mod download -json with exit code 1 sometimes prints JSON and sometimes doesn't #35380
What did you do?
I tried to execute
What did you expect to see?
I expected non-zero exit code to mean a fatal problem occurred and that I should not expect valid JSON output.
What did you see instead?
There are 3 possible scenarios:
In two of the scenarios the exit code is 1. One of them emits JSON. That is challenging for a tool that needs to parse the output; it's hard to be sure it's safe to expect/parse JSON on stdout when exit code is non-zero.
I guess the remaining usability problem is that it's still necessary for caller to parse as JSON even when exit code is 1. And exit code 1 may mean "there are JSON objects to be read and processed", or it could mean "there was a fatal error that prevented go mod download from starting", and it's not easy to tell those apart.