googleapis / googleapis/gapic-generator-ruby

fix(spanner): convert enumerable GRPC::BadStatus errors to Google::Cloud::Errors

Open
#509 4 comments 0 reactions 0 assignees View on GitHub
api: spanner priority: p3 type: feature request
Dominant language
Ruby
Stars
50
Forks
36
Avg merge
1d 1h
Merged PRs (30d)
6

Description

TLDR: we would like to have the conversion of `GRPC::BadStatus` errors to `Google::Cloud::Error`s in the `Enumerable` result of streaming calls of the spanner client, so that the consumer only has to deal with one kind of error.

We are currently observing a problem when calling the streaming calls in the spanner client `Google::Cloud::Spanner::V1::Client` where we have to handle both `Google::Cloud::Error`s and `GRPC::Error`s.

The generated client is rescuing `GRPC::BadStatus` and converting those to `Google::Cloud::Error`s (like [here](https://github.com/googleapis/google-cloud-ruby/blob/master/google-cloud-spanner-v1/lib/google/cloud/spanner/v1/spanner/client.rb#L912)). That is fine, because we can rely that if we get a `GRPC::BadStatus` it will be automatically converted to us when executing the method.

The problem lies in handling the result of streaming calls. The generated client is returning `Enumerable` (as specified [here](https://github.com/googleapis/google-cloud-ruby/blob/master/google-cloud-spanner-v1/lib/google/cloud/spanner/v1/spanner/client.rb#L908-L911)). If we call `result.next` we might get `GRPC::BadStatus` errors, because in this stream of results there is no conversion from `GRPC::BadStatus` errors to `Google::Cloud::Error`s. This makes it a bit clunky to deal with the errors, where we have to deal with both flavours of the same errors.

This problem is exemplified below:

```ruby
require "google/cloud/spanner/v1"

client = V1::Spanner::Client.new

begin
result = client.execute_streaming_sql request, opts # This can raise a Google::Cloud::Error
result.next # This can raise a GRPC::BadStatus (or other GRPC errors)
rescue GRPC::Unavailable, Google::Cloud::UnavailableError => err # Must rescue both
puts err
end
```

We have identified this problem when fixing long PDML transactions in the ruby spanner client library (https://github.com/googleapis/google-cloud-ruby/pull/7592).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.