Nov 9, 2010

ruby-dbus 0.5.0 is a Gem with Errors

I have made a new release of ruby-dbus, a Ruby language binding for the D-Bus IPC system.
The main feature is a better binding of Ruby Exceptions to D-Bus Errors. See below for an excerpt of the documentation.
Perhaps more importantly, the library is now primarily packaged as a RubyGem (Issue#6). Also I converted the tutorial from Webgen to Markdown.
Bug fixes:
  • Don't pass file descriptors to subprocesses, they would not let go of the service name.
  • Fixed InterfaceElement::validate_name (Ticket#38, by Herwin Weststrate).
  • Fixed a typo in InvalidDestinationName description (Ticket#40).
RPMs can be found via openSUSE Build Service Search.

Errors

D-Bus calls can reply with an error instead of a return value. An error is translated to a Ruby exception.
begin
    network_manager.sleep
rescue DBus::Error => e
    puts e unless e.name == "org.freedesktop.NetworkManager.AlreadyAsleepOrAwake"
end

Replying with an error

To reply to a dbus_method with a D-Bus error, raise a DBus::Error, as constructed by the error convenience function:
raise DBus.error("org.example.Error.SeatOccupied"), "Seat #{seat} is occupied"
If the error name is not specified, the generic org.freedesktop.DBus.Error.Failed is used.
raise DBus.error, "Seat #{seat} is occupied"
raise DBus.error

No comments: