Skip to content

Commit

Permalink
python: catch more DBus exceptions
Browse files Browse the repository at this point in the history
Gio.bus_get_sync may return None when the DBus service is not available (see
libratbag/piper#2). In addition to this, the service may time out when it is
being started in which case Gio.DBusProxy.new_sync will raise a GLib.Gerror.

This commit checks for both scenarios and raises a RatbagdDBusUnavailable
exception when either one of them occurs. This will in turn be caught in for
example Piper to properly deal with this.
  • Loading branch information
Hjdskes authored and whot committed Mar 30, 2017
1 parent fc874c0 commit 9601ba1
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions python/ratbagd/__init__.py
Expand Up @@ -35,13 +35,20 @@ class RatbagdDBusUnavailable(BaseException):
class _RatbagdDBus(object):
def __init__(self, interface, object_path):
self._dbus = Gio.bus_get_sync(Gio.BusType.SYSTEM, None)
self._proxy = Gio.DBusProxy.new_sync(self._dbus,
Gio.DBusProxyFlags.NONE,
None,
'org.freedesktop.ratbag1',
object_path,
'org.freedesktop.ratbag1.{}'.format(interface),
None)
if self._dbus is None:
raise RatbagdDBusUnavailable()

try:
self._proxy = Gio.DBusProxy.new_sync(self._dbus,
Gio.DBusProxyFlags.NONE,
None,
'org.freedesktop.ratbag1',
object_path,
'org.freedesktop.ratbag1.{}'.format(interface),
None)
except GLib.GError:
raise RatbagdDBusUnavailable()

if self._proxy.get_name_owner() == None:
raise RatbagdDBusUnavailable()

Expand All @@ -60,6 +67,8 @@ class Ratbagd(_RatbagdDBus):
The ratbagd top-level object. Provides a list of devices available
through ratbagd, actual interaction with the devices is via the
RatbagdDevice, RatbagdProfile and RatbagdResolution objects.
Throws RatbagdDBusUnavailable when the DBus service is not available.
"""
def __init__(self):
_RatbagdDBus.__init__(self, "Manager", '/org/freedesktop/ratbag1')
Expand Down

0 comments on commit 9601ba1

Please sign in to comment.