Exception: Gitlab::Git::BaseError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/gitlab/git/base_error.rb

Constant Summary collapse

METADATA_KEY =
:gitaly_error_metadata
DEBUG_ERROR_STRING_REGEX =
/(.*?) debug_error_string:.*$/m
GRPC_CODES =
{
  '0' => 'ok',
  '1' => 'cancelled',
  '2' => 'unknown',
  '3' => 'invalid_argument',
  '4' => 'deadline_exceeded',
  '5' => 'not_found',
  '6' => 'already_exists',
  '7' => 'permission_denied',
  '8' => 'resource_exhausted',
  '9' => 'failed_precondition',
  '10' => 'aborted',
  '11' => 'out_of_range',
  '12' => 'unimplemented',
  '13' => 'internal',
  '14' => 'unavailable',
  '15' => 'data_loss',
  '16' => 'unauthenticated'
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(msg = nil) ⇒ BaseError

Returns a new instance of BaseError.



31
32
33
34
35
36
37
38
39
40
# File 'lib/gitlab/git/base_error.rb', line 31

def initialize(msg = nil)
  super && return if msg.nil?

  if msg.is_a?(::GRPC::BadStatus)
    set_grpc_error_code(msg)
    (msg)
  end

  super(build_raw_message(msg))
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



29
30
31
# File 'lib/gitlab/git/base_error.rb', line 29

def code
  @code
end

#metadataObject (readonly)

Returns the value of attribute metadata.



29
30
31
# File 'lib/gitlab/git/base_error.rb', line 29

def 
  @metadata
end

#serviceObject (readonly)

Returns the value of attribute service.



29
30
31
# File 'lib/gitlab/git/base_error.rb', line 29

def service
  @service
end

#statusObject (readonly)

Returns the value of attribute status.



29
30
31
# File 'lib/gitlab/git/base_error.rb', line 29

def status
  @status
end

Instance Method Details

#build_raw_message(message) ⇒ Object



42
43
44
45
46
# File 'lib/gitlab/git/base_error.rb', line 42

def build_raw_message(message)
  raw_message = message.to_s
  match = DEBUG_ERROR_STRING_REGEX.match(raw_message)
  match ? match[1] : raw_message
end

#set_grpc_error_code(grpc_error) ⇒ Object



48
49
50
51
52
# File 'lib/gitlab/git/base_error.rb', line 48

def set_grpc_error_code(grpc_error)
  @status = grpc_error.code
  @code = GRPC_CODES[@status.to_s]
  @service = 'git'
end

#set_grpc_error_metadata(grpc_error) ⇒ Object



54
55
56
# File 'lib/gitlab/git/base_error.rb', line 54

def (grpc_error)
  @metadata = grpc_error..fetch(METADATA_KEY, {}).clone
end