Class: Google::Cloud::Spanner::Status

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/spanner/status.rb

Overview

# Status

Represents a logical error model from the Spanner service, containing an error code, an error message, and optional error details.

Examples:

require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new

job = spanner.create_database "my-instance",
                              "my-new-database"

job.error? # true

status = job.error

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code, description, message, details) ⇒ Status

Returns a new instance of Status.



55
56
57
58
59
60
# File 'lib/google/cloud/spanner/status.rb', line 55

def initialize code, description, message, details
  @code = code
  @description = description
  @message = message
  @details = details
end

Instance Attribute Details

#codeInteger

The status code, which should be an enum value of [google.rpc.Code](github.com/googleapis/googleapis/blob/master/google/rpc/code.proto).

Returns:

  • (Integer)

    the current value of code



50
51
52
# File 'lib/google/cloud/spanner/status.rb', line 50

def code
  @code
end

#descriptionString

The human-readable description for the status code, which should be an enum value of [google.rpc.Code](github.com/googleapis/googleapis/blob/master/google/rpc/code.proto). For example, ‘INVALID_ARGUMENT`.

Returns:

  • (String)

    the current value of description



50
51
52
# File 'lib/google/cloud/spanner/status.rb', line 50

def description
  @description
end

#detailsArray?

A list of messages that carry the error details.

Returns:

  • (Array, nil)

    the current value of details



50
51
52
# File 'lib/google/cloud/spanner/status.rb', line 50

def details
  @details
end

#messageString

A developer-facing error message, which should be in English.

Returns:

  • (String)

    the current value of message



50
51
52
# File 'lib/google/cloud/spanner/status.rb', line 50

def message
  @message
end

Class Method Details

.description_for(code) ⇒ Object



69
70
71
72
73
74
75
76
77
# File 'lib/google/cloud/spanner/status.rb', line 69

def self.description_for code
  descriptions = %w(
    OK CANCELLED UNKNOWN INVALID_ARGUMENT DEADLINE_EXCEEDED NOT_FOUND
    ALREADY_EXISTS PERMISSION_DENIED RESOURCE_EXHAUSTED
    FAILED_PRECONDITION ABORTED OUT_OF_RANGE UNIMPLEMENTED INTERNAL
    UNAVAILABLE DATA_LOSS UNAUTHENTICATED
  )
  descriptions[code]
end

.from_grpc(grpc) ⇒ Object



64
65
66
# File 'lib/google/cloud/spanner/status.rb', line 64

def self.from_grpc grpc
  new grpc.code, description_for(grpc.code), grpc.message, grpc.details
end