Exception: GRPC::BadStatus
- Inherits:
-
StandardError
- Object
- StandardError
- GRPC::BadStatus
- Includes:
- Core::StatusCodes
- Defined in:
- src/ruby/lib/grpc/errors.rb
Overview
BadStatus is an exception class that indicates that an error occurred at either end of a GRPC connection. When raised, it indicates that a status error should be returned to the other end of a GRPC connection; when caught it means that this end received a status error.
There is also subclass of BadStatus in this module for each GRPC status. E.g., the GRPC::Cancelled class corresponds to status CANCELLED.
See github.com/grpc/grpc/blob/master/include/grpc/impl/codegen/status.h for detailed descriptions of each status code.
Direct Known Subclasses
Aborted, AlreadyExists, Cancelled, DataLoss, DeadlineExceeded, FailedPrecondition, Internal, InvalidArgument, NotFound, Ok, OutOfRange, PermissionDenied, ResourceExhausted, Unauthenticated, Unavailable, Unimplemented, Unknown
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#details ⇒ Object
readonly
Returns the value of attribute details.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(code, details = 'unknown cause', metadata = {}) ⇒ BadStatus
constructor
A new instance of BadStatus.
-
#to_rpc_status ⇒ Google::Rpc::Status?
Converts the exception to a deserialized Google::Rpc::Status object.
-
#to_status ⇒ Struct::Status
Converts the exception to a Struct::Status for use in the networking wrapper layer.
Constructor Details
#initialize(code, details = 'unknown cause', metadata = {}) ⇒ BadStatus
Returns a new instance of BadStatus.
38 39 40 41 42 43 |
# File 'src/ruby/lib/grpc/errors.rb', line 38 def initialize(code, details = 'unknown cause', = {}) super("#{code}:#{details}") @code = code @details = details @metadata = end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
31 32 33 |
# File 'src/ruby/lib/grpc/errors.rb', line 31 def code @code end |
#details ⇒ Object (readonly)
Returns the value of attribute details.
31 32 33 |
# File 'src/ruby/lib/grpc/errors.rb', line 31 def details @details end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
31 32 33 |
# File 'src/ruby/lib/grpc/errors.rb', line 31 def @metadata end |
Class Method Details
.new_status_exception(code, details = 'unknown cause', metadata = {}) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'src/ruby/lib/grpc/errors.rb', line 72 def self.new_status_exception(code, details = 'unknown cause', = {}) codes = {} codes[OK] = Ok codes[CANCELLED] = Cancelled codes[UNKNOWN] = Unknown codes[INVALID_ARGUMENT] = InvalidArgument codes[DEADLINE_EXCEEDED] = DeadlineExceeded codes[NOT_FOUND] = NotFound codes[ALREADY_EXISTS] = AlreadyExists codes[PERMISSION_DENIED] = PermissionDenied codes[UNAUTHENTICATED] = Unauthenticated codes[RESOURCE_EXHAUSTED] = ResourceExhausted codes[FAILED_PRECONDITION] = FailedPrecondition codes[ABORTED] = Aborted codes[OUT_OF_RANGE] = OutOfRange codes[UNIMPLEMENTED] = Unimplemented codes[INTERNAL] = Internal codes[UNAVAILABLE] = Unavailable codes[DATA_LOSS] = DataLoss if codes[code].nil? BadStatus.new(code, details, ) else codes[code].new(details, ) end end |
Instance Method Details
#to_rpc_status ⇒ Google::Rpc::Status?
Converts the exception to a deserialized Google::Rpc::Status object. Returns ‘nil` if the `grpc-status-details-bin` trailer could not be converted to a Google::Rpc::Status due to the server not providing the necessary trailers.
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'src/ruby/lib/grpc/errors.rb', line 59 def to_rpc_status # Lazily require google_rpc_status_utils to scope # loading protobuf_c.so to the users of this method. require_relative './google_rpc_status_utils' status = to_status return if status.nil? GoogleRpcStatusUtils.extract_google_rpc_status(status) rescue Google::Protobuf::ParseError => parse_error GRPC.logger.warn('parse error: to_rpc_status failed') GRPC.logger.warn(parse_error) nil end |
#to_status ⇒ Struct::Status
Converts the exception to a Struct::Status for use in the networking wrapper layer.
49 50 51 |
# File 'src/ruby/lib/grpc/errors.rb', line 49 def to_status Struct::Status.new(code, details, ) end |