Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Raise a unique exception if libvirt C library not available.

  • Loading branch information...
commit 942d213191918ed0bc7aa5a6b62a1f0bc8d96bbb 1 parent d06c4ae
@mitchellh authored
View
3  CHANGELOG.md
@@ -1,6 +1,7 @@
## 0.2.1 (unreleased)
-
+ - `FFI::Libvirt::MissingLibError` is raised if libvirt C library
+ is not available.
## 0.2.0 (December 7, 2010)
View
2  Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
- libvirt (0.2.0)
+ libvirt (0.2.1.dev)
ffi (~> 0.6.3)
nokogiri (~> 1.4.3)
View
13 lib/ffi/libvirt.rb
@@ -7,10 +7,19 @@ module FFI
# that it is up to you to manage all the pointers and so on that come
# with this power.
module Libvirt
+ autoload :MissingLibError, 'ffi/libvirt/exception'
+ autoload :Util, 'ffi/libvirt/util'
+
extend FFI::Library
- ffi_lib "libvirt"
- autoload :Util, 'ffi/libvirt/util'
+ # Attempt to load the libvirt lib and raise a more specific exception
+ # if it doesn't exist. (Normally a LoadError, which is ambiguous, is
+ # raised)
+ begin
+ ffi_lib "libvirt"
+ rescue LoadError
+ raise MissingLibError
+ end
end
end
View
10 lib/ffi/libvirt/exception.rb
@@ -0,0 +1,10 @@
+module FFI
+ module Libvirt
+ # Error raised when the libvirt C library is missing.
+ class MissingLibError < StandardError
+ def initialize
+ super("The libvirt C library could not be loaded. Is it properly installed?")
+ end
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.