Class: Libvirt::Error
- Inherits:
-
Object
- Object
- Libvirt::Error
- 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
-
#interface ⇒ Object
readonly
Returns the value of attribute interface.
Class Method Summary collapse
-
.last_error ⇒ Error
Gets the last error (if there is one) and returns the Error representing it.
-
.on_error(&block) ⇒ Object
Sets an error handling function.
-
.raise_errors ⇒ Boolean
Returns whether or not Libvirt is currently configured to raise errors automatically when it is reported.
-
.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.
Instance Method Summary collapse
-
#code ⇒ Symbol
Returns the error code of the error.
-
#domain ⇒ Symbol
Returns the domain or "category" in which this error occured.
-
#initialize(pointer) ⇒ Error
constructor
Initializes a new error object.
-
#message ⇒ String
Returns a human-friendly message related to the error.
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
#interface ⇒ Object (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_error ⇒ Error
Gets the last error (if there is one) and returns the Libvirt::Error representing it.
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_errors ⇒ Boolean
Returns whether or not Libvirt is currently configured to raise errors automatically when it is reported.
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.
39 40 41 |
# File 'lib/libvirt/error.rb', line 39 def raise_errors=(value) @@raise_errors = !!value end |
Instance Method Details
#code ⇒ Symbol
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.
71 72 73 |
# File 'lib/libvirt/error.rb', line 71 def code interface[:code] end |
#domain ⇒ Symbol
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
.
80 81 82 |
# File 'lib/libvirt/error.rb', line 80 def domain interface[:domain] end |
#message ⇒ String
Returns a human-friendly message related to the error.
87 88 89 |
# File 'lib/libvirt/error.rb', line 87 def interface[:message] end |