-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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 does not output json when sumdb fails #34485
Comments
That seems reasonable to me, but I'd like to confirm with @FiloSottile or @rsc . (CC @jayconrod) |
There are always going to be ways the go command fails and prints to standard error without producing JSON on standard output. Why not treat this failure like any other such failure? Why does it have to be encoded in JSON on standard output? |
Another option is maybe base.Fatalf should be printing the JSON during -json mode. That would be a much smaller patch. |
Does that mean that go proxies should always try to parse json from stdout (on failure and success) and if the parsing fails they need to read stderr as the alternate failure message?
That's kind of what I expected. "Any other such failure" does produce valid json, therefore I expected the sumdb failure to also behave similarly. For example the following command fails, but produces valid json:
While the same exact command fails (for a different reason), but does not produce a valid json:
The issue is that some json data will be lost or may not even be the same shape, for example: While So I imagine base.Fatalf will probably have its own json shape that describes the error and potential extra information. That sounds good but the issue is that at this moment, running If the patch is to change all errors to use base.Fatalf shape, then that will be consistent, but I imagine that's an equally large change to the codebase. But maybe you had something else in mind for how the go proxies should deal with Thanks for the quick response! |
I agree that proxies should be robust to missing JSON output. On the other hand, I suspect that we will need to convert many calls to So I'm not sure that |
Change https://golang.org/cl/197062 mentions this issue: |
Summary
go mod download -json
still returns a valid json when the command fails.For example, if you run
go mod download -json github.com/alsdkfjjsdkfjk/alskdfjksdjf@v1.0.0
then Stdout receives a valid json with the error message saying "module not found".However, say you have a private repo you'd like to
go mod download -json
, but you haven't configured GOPRIVATE/GONOSUMDB correctly, then the command fails as expected, but the output is not json.Digging a little more, I see that most sumdb-checking functions just call
base.Fatalf
and not actually return an error.Here's what I had to do to fix it: marwan-at-work@f143bce
I'd be happy to submit the commit above as a CL if it looks okay as a fix
What version of Go are you using (
go version
)?1.13
Does this issue reproduce with the latest release?
Yes
What did you do?
GONOSUMDB='' go mod download -json <private-repo>@<version>
What did you expect to see?
A valid json with the
Error
field describing that the sumdb check has failed.What did you see instead?
A non-valid-json with the expected error message
The text was updated successfully, but these errors were encountered: