-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Open
Labels
Description
What version of gRPC are you using?
1.74.2
What version of Go are you using (go version
)?
go version go1.24.4 darwin/arm64
What operating system (Linux, Windows, …) and version?
macOS Sequoia 15.6
What did you do?
I want to wrap a gRPC status error and be able to receive the original proto message. This PR #6150 makes it unexpectedly hard because I can not use status.FromError
.
Here is an example:
err := fmt.Errorf("prefix: %w", status.Error(codes.NotFound, "description"))
raw := status.Convert(err).Proto()
println(raw.Message) // prefix: rpc error: code = NotFound desc = description
err = status.Convert(err).Err()
println(err.Error()) // rpc error: code = NotFound desc = prefix: rpc error: code = NotFound desc = description
What did you expect to see?
I expect to see the original message from the server.
println(raw.Message) // description
What did you see instead?
I see the full wrapped error message.
Workaround
I have to use a custom unwrapper to get the original proto message.
func Original(err error) *status.Status {
var gs interface{ GRPCStatus() *status.Status }
if errors.As(err, &gs) {
grpcStatus := gs.GRPCStatus()
if grpcStatus != nil {
return grpcStatus
}
}
return status.New(codes.Unknown, err.Error())
}