Exception: GRPC::BadStatus

Inherits:
StandardError
  • Object
show all
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.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code, details = 'unknown cause', metadata = {}) ⇒ BadStatus

Returns a new instance of BadStatus.

Parameters:

  • code (Numeric)

    the status code

  • details (String) (defaults to: 'unknown cause')

    the details of the exception

  • metadata (Hash) (defaults to: {})

    the error’s metadata



53
54
55
56
57
58
# File 'src/ruby/lib/grpc/errors.rb', line 53

def initialize(code, details = 'unknown cause',  = {})
  super("#{code}:#{details}")
  @code = code
  @details = details
  @metadata = 
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



46
47
48
# File 'src/ruby/lib/grpc/errors.rb', line 46

def code
  @code
end

#detailsObject (readonly)

Returns the value of attribute details.



46
47
48
# File 'src/ruby/lib/grpc/errors.rb', line 46

def details
  @details
end

#metadataObject (readonly)

Returns the value of attribute metadata.



46
47
48
# File 'src/ruby/lib/grpc/errors.rb', line 46

def 
  @metadata
end

Class Method Details

.new_status_exception(code, details = 'unkown cause', metadata = {}) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'src/ruby/lib/grpc/errors.rb', line 68

def self.new_status_exception(code, details = 'unkown 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[UNIMPLEMENTED] =  Unimplemented
  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_statusStatus

Converts the exception to a GRPC::Status for use in the networking wrapper layer.

Returns:

  • (Status)

    with the same code and details



64
65
66
# File 'src/ruby/lib/grpc/errors.rb', line 64

def to_status
  Struct::Status.new(code, details, @metadata)
end