Class: Libvirt::Error

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

Overview

Represents the actual libvirt error object which most erroneous events set. This contains important information such as the message, domain, etc.

Constant Summary collapse

ERROR_HANDLER_PROC =

This proc needs to be assigned to a constant so that it is never GC'd and can be assigned as a callback to the API.

method(:error_handler)
@@error_block =
nil
@@raise_errors =
true

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pointer) ⇒ Error

Initializes a new error object. This shouldn't be called publicly. Instead use last_error or obtain the error from any of the exceptions which the library raises.



62
63
64
# File 'lib/libvirt/error.rb', line 62

def initialize(pointer)
  @interface = FFI::Libvirt::Error.new(pointer)
end

Instance Attribute Details

#interfaceObject (readonly)

Returns the value of attribute interface.



9
10
11
# File 'lib/libvirt/error.rb', line 9

def interface
  @interface
end

Class Method Details

.last_errorError

Gets the last error (if there is one) and returns the Libvirt::Error representing it.

Returns:



16
17
18
19
20
# File 'lib/libvirt/error.rb', line 16

def last_error
  pointer = FFI::Libvirt.virGetLastError
  return nil if pointer.null?
  new(pointer)
end

.on_error(&block) ⇒ Object

Sets an error handling function. This will call the given block whenever an error occurs within libvirt.



24
25
26
# File 'lib/libvirt/error.rb', line 24

def on_error(&block)
  @@error_block = block
end

.raise_errorsBoolean

Returns whether or not Libvirt is currently configured to raise errors automatically when it is reported.

Returns:

  • (Boolean)


32
# File 'lib/libvirt/error.rb', line 32

def raise_errors; @@raise_errors; end

.raise_errors=(value) ⇒ Object

Set this to a boolean true/false to control whether the library automatically raises Libvirt::Exception::LibvirtError whenever an error occurs.

Parameters:

  • value (Boolean)


39
40
41
# File 'lib/libvirt/error.rb', line 39

def raise_errors=(value)
  @@raise_errors = !!value
end

Instance Method Details

#codeSymbol

Returns the error code of the error. Internally, this is represented by a C enum, so this will actually return a Ruby Symbol representation of the error.

Returns:

  • (Symbol)


71
72
73
# File 'lib/libvirt/error.rb', line 71

def code
  interface[:code]
end

#domainSymbol

Returns the domain or "category" in which this error occured. This is represented internally as a C enum, so this will actually return a Ruby symbol.

Returns:

  • (Symbol)


80
81
82
# File 'lib/libvirt/error.rb', line 80

def domain
  interface[:domain]
end

#messageString

Returns a human-friendly message related to the error.

Returns:

  • (String)


87
88
89
# File 'lib/libvirt/error.rb', line 87

def message
  interface[:message]
end