You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
INFO stats msg="status error"
INFO stats from error msg="status error"
INFO stats from wrapped error msg="rpc error: code = Code(400) desc = status error\nwrapper"
You will see the original message didn't change by calling status.FromError(statusErr), which is expected.
But, the original message status error become rpc error: code = Code(400) desc = status error\nwrapper after joining a wrapper error errors.Join(statusErr, errors.New("wrapper")). The status after this becomes not the original one.
The new message not just include the message wrapper from wrapper (this is strange), but also include the a rendered status string string rpc error: code = Code(400) desc = . I am not sure including a rendered string in the Message field of the status itself make sense.
Even worse, when I called statsFromWrappedErr.String(). I got
For those who relies on this current behavior, they could always use this to append the error string after calling status.FromError.
p := statsFromErr.Proto()
p.Message = statusErr.Error()
newStats := status.FromProto(p)
But, for those who want their original status, they can only fork their own version of status.FormError since the status returned by status.FormError has been contaminated.
Inconsistent behavior
The second issue is about consistency.
While it can retrieve original status from an error that implements grpcstatus interface
But, the original message status error become rpc error: code = Code(400) desc = status error\nwrapper after joining a wrapper error errors.Join(statusErr, errors.New("wrapper")). The status after this becomes not the original one.
It return a modified status from an error that also implements grpcstatus interface but wrapped
I believe I looked into some other libraries and saw similar behavior before we made this change. It is a bit unfortunate that the new Message contains the status code again, but I don't think there's any other way to get the wrapped error text without that happening.
Aside from theoretical problems or a dislike for the result, do you have any real problems that this creates?
It is a bit unfortunate that the new Message contains the status code again, but I don't think there's any other way to get the wrapped error text without that happening.
I am not sure why injecting a wrapped error text would become a feature of status.FromError in the first place, especially err.Error() can always return the wrapped error text.
do you have any real problems that this creates?
If a counter-intuitive result and inconsistent behavior are not considered real problems, then I don't have real problems that this creates.
Use case(s) - what problem will this feature solve?
The current implementation of
status.FromError
has two issues:original status message is changed with
errors.Join
Considering this code
The output is something like
You will see the original message didn't change by calling
status.FromError(statusErr)
, which is expected.But, the original message
status error
becomerpc error: code = Code(400) desc = status error\nwrapper
after joining a wrapper errorerrors.Join(statusErr, errors.New("wrapper"))
. The status after this becomes not the original one.The new message not just include the message
wrapper
from wrapper (this is strange), but also include the a rendered status string stringrpc error: code = Code(400) desc =
. I am not sure including a rendered string in theMessage
field of the status itself make sense.Even worse, when I called
statsFromWrappedErr.String()
. I gotThis behavior looks strange and has a code smell.
For those who relies on this current behavior, they could always use this to append the error string after calling
status.FromError
.But, for those who want their original status, they can only fork their own version of
status.FormError
since the status returned bystatus.FormError
has been contaminated.Inconsistent behavior
The second issue is about consistency.
While it can retrieve original status from an error that implements
grpcstatus interface
grpc-go/status/status.go
Lines 101 to 111 in 4cedec4
It return a modified status from an error that also implements
grpcstatus interface
but wrappedgrpc-go/status/status.go
Lines 112 to 125 in 4cedec4
These two serve a similar purpose (find the status) by different way but returning different results. This seems inconsistent.
Proposed Solution
revert #6150
Additional Context
I am happy to create a PR for this.
The text was updated successfully, but these errors were encountered: