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.wait_until_done!

if job.error?
  status = job.error
end

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.



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

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



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

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



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

def description
  @description
end

#detailsArray?

A list of messages that carry the error details.

Returns:

  • (Array, nil)

    the current value of details



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

def details
  @details
end

#messageString

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

Returns:

  • (String)

    the current value of message



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

def message
  @message
end

Class Method Details

.description_for(code) ⇒ Object



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

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



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

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