spanner: GRPCStatus always returns a status based on specified Code
This change fixes the behavior of GRPCStatus of Error that always
returns a Status based on Code field of Error.
Current implementation returns a Status that has Unknown code if the
base error is nil.
Change-Id: I832338d750396677b9e95d94613c78921493166f
Reviewed-on: https://code-review.googlesource.com/c/gocloud/+/51113
Reviewed-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Knut Olav Løite <koloite@gmail.com>
Reviewed-by: Hengfeng Li <hengfeng@google.com>
diff --git a/spanner/errors.go b/spanner/errors.go
index 547a6af..82f39e8 100644
--- a/spanner/errors.go
+++ b/spanner/errors.go
@@ -69,10 +69,9 @@
func (e *Error) GRPCStatus() *status.Status {
err := unwrap(e)
for {
- // No gRPC Status found in the chain of errors. Return 'Unknown' with
- // the message of the original error.
+ // If the base error is nil, return status created from e.Code and e.Desc.
if err == nil {
- return status.New(codes.Unknown, e.Desc)
+ return status.New(e.Code, e.Desc)
}
code := status.Code(err)
if code != codes.Unknown {