Exception: Libvirt::Errors::LibError

Inherits:
Error
  • Object
show all
Defined in:
lib/libvirt/errors.rb

Constant Summary collapse

ERROR_FIELDS =

Object contains detailed error information retrieved from libvirt.

[:code, :domain, :message, :level].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client_message = nil) ⇒ LibError

When client_message ommited and virGetLastError return error message will be following: “ERROR_LEVEL: ERROR_NUMBER (ERROR_DOMAIN) ERROR_MESSAGE”. When client message provided and virGetLastError return error message will be following: “CLIENT_MESSAGEnERROR_LEVEL: ERROR_NUMBER (ERROR_DOMAIN) ERROR_MESSAGE”. When client message is provided and virGetLastError return no error message will be following: “CLIENT_MESSAGE”.

Parameters:

  • client_message (String, nil) (defaults to: nil)

    optional client message



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/libvirt/errors.rb', line 28

def initialize(client_message = nil)
  @client_message = client_message
  ptr = FFI::Error.virGetLastError
  unless ptr.null?
    struct = FFI::Error::Struct.new(ptr)
    @error_data = struct.members.map { |m| [m, struct[m]] }.to_h
    @error_code = error_data[:code]
    @error_domain = error_data[:domain]
    @error_message = error_data[:message]
    @error_level = error_data[:level]
  end

  super(build_message)
end

Instance Attribute Details

#client_messageObject (readonly)

Returns the value of attribute client_message.



14
15
16
# File 'lib/libvirt/errors.rb', line 14

def client_message
  @client_message
end

#error_codeObject (readonly)

Returns the value of attribute error_code.



14
15
16
# File 'lib/libvirt/errors.rb', line 14

def error_code
  @error_code
end

#error_dataObject (readonly)

Returns the value of attribute error_data.



14
15
16
# File 'lib/libvirt/errors.rb', line 14

def error_data
  @error_data
end

#error_domainObject (readonly)

Returns the value of attribute error_domain.



14
15
16
# File 'lib/libvirt/errors.rb', line 14

def error_domain
  @error_domain
end

#error_levelObject (readonly)

Returns the value of attribute error_level.



14
15
16
# File 'lib/libvirt/errors.rb', line 14

def error_level
  @error_level
end

#error_messageObject (readonly)

Returns the value of attribute error_message.



14
15
16
# File 'lib/libvirt/errors.rb', line 14

def error_message
  @error_message
end