Skip to content

Commit 11718bb

Browse files
authored
better jeepney error text (#188)
If dbus-based method is failing because DBUS_SESSION_BUS_ADDRESS is not set, give better error message
1 parent a262987 commit 11718bb

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

wakepy/dbus_adapters/jeepney.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
from wakepy.core import DbusAdapter, DbusMethodCall
66

77

8+
class DbusNotFoundError(RuntimeError):
9+
...
10+
11+
812
class JeepneyDbusAdapter(DbusAdapter):
913
"""An implementation of DbusAdapter using jeepney. Can be used to process
1014
DbusMethodCalls (communication with Dbus services over a dbus-daemon)."""
@@ -25,7 +29,18 @@ def process(self, call: DbusMethodCall):
2529
signature=call.method.signature,
2630
body=call.args,
2731
)
28-
connection = open_dbus_connection(bus=call.method.bus)
32+
try:
33+
connection = open_dbus_connection(bus=call.method.bus)
34+
except KeyError as exc:
35+
if "DBUS_SESSION_BUS_ADDRESS" in str(exc):
36+
raise DbusNotFoundError(
37+
"The environment variable DBUS_SESSION_BUS_ADDRESS is not set! "
38+
"To use dbus-based methods with jeepney, a session (not system) "
39+
"bus (dbus-daemon process) must be running, and the address of the "
40+
"bus should be available at the DBUS_SESSION_BUS_ADDRESS "
41+
"environment variable. To check if you're running a session "
42+
"dbus-daemon, run `ps -x | grep dbus-daemon`"
43+
) from exc
2944
reply = connection.send_and_get_reply(msg, timeout=self.timeout)
3045
resp = unwrap_msg(reply)
3146
return resp

0 commit comments

Comments
 (0)