spanner.client.readWriteTransaction() doesn't actually return client-provided error
From client.readWriteTransaction function comment: // If f returns an error other than IsAborted, ReadWriteTransaction will abort the // transaction and return the error.
This makes it sound like the client-provided error object from f will be returned. But in practice, the library returns spanner: code = "Unknown" and puts the client-provided error info in the desc field. It seems we should either update the documentation, or change the implementation. Here's a quick repro:
ctx, _ := context.WithTimeout(context.Background(), 20*time.Second)
var ErrFoo = errors.New("Foo error")
_, err := client.ReadWriteTransaction(ctx, func(ctx context.Context, txn *spanner.ReadWriteTransaction) error {
return ErrFoo
})
if err != nil {
if err == ErrFoo {
log.Print("MATCH")
} else {
log.Print("NO MATCH")
log.Printf("Expected: %s\nGot: %s", ErrFoo, err)
}
}
return err
Output:
Expected: Foo error
Got: spanner: code = "Unknown", desc = "Foo error"
p.s. - I'm a Go n00b, so feel free to tell me this is the right behavior.
The Spanner client likes to return spanner.Error everywhere. In this case we should make an exception.
https://code-review.googlesource.com/#/c/gocloud/+/18950