google-cloud-go icon indicating copy to clipboard operation
google-cloud-go copied to clipboard

spanner.client.readWriteTransaction() doesn't actually return client-provided error

Open mcurtiss opened this issue 9 years ago • 2 comments

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"

mcurtiss avatar Oct 27 '17 17:10 mcurtiss

p.s. - I'm a Go n00b, so feel free to tell me this is the right behavior.

mcurtiss avatar Oct 27 '17 17:10 mcurtiss

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

jba avatar Oct 27 '17 19:10 jba