-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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: define error codes and use them to describe errors. #30134
Comments
In general the go command does not know an accurate error. It ran a helper program like git and that command fails. Trying to pull accurate error analysis out of those helper programs is basically futile. If the go command return an error code, what would a caller do differently? The right behavior may be just to retry in 1 minute (or 2 or 3 or 5 or whatever, maybe even with exponential backoff) regardless of what went wrong. I was involved with the great error code page discussions that led to the gRPC HTTP error codes, and honestly I am skeptical that they are that useful in practice. I know the go command does not have available the information necessary to select the right one. Even "permanent" errors are only permanent until a person fixes them. |
@rsc error codes from go would be highly beneficial and important for a GOPROXY for two reasons:
There are also other examples about determining behavior based on error codes which I'm happy to mention as well if need be. |
I think we should leave this for Go 1.14. |
Go command, particularly,
go list
andgo mod download
, now serves as the canonical way to retrieve information about modules and packages. Programs and libraries that need to understand how Go handles build and interprets source code are supposed to invoke the command and interpret the command's output. For example,golang.org/x/tools/go/packages
depends on invocation ofgo list
, and we expect some module proxies to utilizego mod download
orgo list
.Go command provides -json and other flags to output in a structured form to ease the result parsing. But, handling error cases programmatically is still difficult. To be useful like a library, Go command line tool output should allow programs to distinguish different failure cases (invalid arguments, failed precondition, resource unavailability (network, tool, disk, ...) , permission issue, ...).
Currently,
Command line exit code: Go command exits with a non-zero exit code for "some" error cases (often 1). But this exit code doesn't carry enough information. Depending on the exit code or error messages from a command line anyway is not a reliable way.
Error/Err fields, as in
-json
orgo list -e -f
results, provide some error details, but they are "string" types. Parsing and depending on the message is not reliable or scalable.One option is that we define a set of status codes (like https://github.com/grpc/grpc/blob/master/doc/statuscodes.md or like HTTP, JSON error codes)
and use that to describe the kind of the error.
(sidenote: I wished Go2 error proposals also covered encoding/decoding of the error types and root causes but it seems that was not discussed.)
Moreover, we also need to fix the Go command to report the root cause of the error accurately.
For example, I ran the following example while I had not network access. Even though the root cause of the failure is the (temporary) network issue, the error message is not distinguishable from what Go returns when the module does not exists.
I am happy to file a separate issue about misleading error messages if there is no existing open issue yet.
@jayconrod @bcmills
@katiehockman @heschik @ianthehat
The text was updated successfully, but these errors were encountered: