Skip to content

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

@thiagotnunes

Description

@thiagotnunes

TLDR: we would like to have the conversion of GRPC::BadStatus errors to Google::Cloud::Errors 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::Errors and GRPC::Errors.

The generated client is rescuing GRPC::BadStatus and converting those to Google::Cloud::Errors (like here). 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<PartialResultSet> (as specified here). 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::Errors. 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:

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 (googleapis/google-cloud-ruby#7592).

Metadata

Metadata

Assignees

No one assigned

    Labels

    api: spannerIssues related to the Spanner API.priority: p3Desirable enhancement or fix. May not be included in next release.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions