-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Implement the errors.Unwrap interface as appropriate #4567
Conversation
- The comment speaks of "future error.Is functionality"; well Go 1.13 has since been released; it isn't "future" anymore. Change "future" to "Go 1.13". - In that same phrase, change "error.Is" to "errors.Is"; since it's referring to the functionality in the "errors" package. - The second sentence starts "A Error"; change that to "An Error".
There are several implementations of `error` that happen to wrap an inner `error`. Have these also implement the standard interface for `errors.Unwrap`.
Nice. Looking forward to this being the default error treatment so that we can always leverage |
Correction: #2934 is about wrapping Status errors inside other errors. I'm not sure this is something we want. The errors coming back from gRPC ( |
@dfawley wrote:
That is not the case / that does not work. Given the code _, err := grpc.Dial("unix:/does/not/exist.sock",
grpc.WithInsecure(),
grpc.WithBlock(),
grpc.FailOnNonTempDialError(true),
)
err := transport.ConnectionError{ // google.golang.org/grpc/internal/transport
Desc: "transport: error while dialing: dial unix /does/not/exist.sock: connect: no such file or directory",
temp: false,
err: &net.OpError{
Op: "dial",
Net: "unix",
Source: nil,
Addr: &net.UnixAddr{
Name: "/does/not/exist.sock",
Net: "unix",
},
Err: syscall.ENOENT,
},
} Because |
@dfawley wrote:
I'm not sure I agree. The
It does not speak of synthesizing statuses for errors not returned over gRPC over the wire. To use statuses that way would be surprising and unexpected to current users. In HTTP client libraries we don't represent network errors as HTTP 500 responses; we differentiet between protocol-errors and errors-sent-over-the-protocol. Between in-band and out-of-band errors. I believe that gRPC libraries should follow the same principle. |
Also note that in the case of |
Note that IMO, considering that, we should really be returning only status errors from
So maybe this is what we can do for now? Implement |
This PR is labeled as requiring an update from the reporter, and no update has been received after 6 days. If no update is provided in the next 7 days, this issue will be automatically closed. |
Since Go 1.13, implementations of
error
that wrap anothererror
should implement anUnwrap() error
method, which will make the error be usable with theerrors.Is
,errors.As
, anderrors.Unwrap
inspection functions.There is an existing ticket about supporting error unwrapping (#2934) but most of what is being talked about in that ticket is about wrapping for gRPC statuses being sent over the network. This PR doesn't deal with that. It just deals with implementing
Wrap
on local error types.It is tempting to also search for
fmt.Errorf("whatever: %v", err)
and change the%v
to%w
, but (1) that would have required either depending on Go 1.13 (compared to the current 1.11) or replacingfmt.Errorf
withgolang.org/x/xerrors.Errorf
, and (2) seemed tedious and I didn't really want to put in the effort. The existing PR covers the errors that I happen to care about.As an example of what this allows: If I dial an AF_UNIX socket that doesn't exist, (
conn, err := grpc.DialContext(ctx, "unix:/path/to/file.sock", ...)
) I can now check for that condition witherrors.Is(err, os.ErrNotExist)
.RELEASE NOTES:
errors.Unwrap
as appropriate.