bridge (D-Bus): fix BridgeException wrapping

This commit is contained in:
Goffi 2026-05-04 16:38:48 +02:00
commit a750154c2f
2 changed files with 34 additions and 4 deletions

View file

@ -48,6 +48,8 @@ def dbus_to_bridge_exception(failure):
@param failure (Failure or RemoteError)
@return: BridgeException
"""
import ast
from twisted.python.failure import Failure
if isinstance(failure, Failure):
@ -68,7 +70,18 @@ def dbus_to_bridge_exception(failure):
else:
name = full_name
return BridgeException(name, message, "")
# The backend GenericException serializes (message, condition) as a tuple string.
# Try to unpack it or fall back to using the raw message with no condition.
condition = ""
try:
data = ast.literal_eval(message)
if isinstance(data, tuple) and len(data) >= 2:
message = data[0]
condition = data[1]
except (ValueError, SyntaxError):
pass
return BridgeException(name, message, condition)
class SignalsHandler:
@ -334,7 +347,9 @@ class TwistedBridge(bridge):
@param args(list): arguments
@param kwargs(dict): keyword arguments (profile, etc.)
"""
return super().call(name, *args, **kwargs)
d = super().call(name, *args, **kwargs)
d.addErrback(self._errback)
return d
async def bridge_connect(self) -> None:
"""Connect to the D-Bus bridge."""

View file

@ -48,6 +48,8 @@ def dbus_to_bridge_exception(failure):
@param failure (Failure or RemoteError)
@return: BridgeException
"""
import ast
from twisted.python.failure import Failure
if isinstance(failure, Failure):
@ -68,7 +70,18 @@ def dbus_to_bridge_exception(failure):
else:
name = full_name
return BridgeException(name, message, "")
# The backend GenericException serializes (message, condition) as a tuple string.
# Try to unpack it or fall back to using the raw message with no condition.
condition = ""
try:
data = ast.literal_eval(message)
if isinstance(data, tuple) and len(data) >= 2:
message = data[0]
condition = data[1]
except (ValueError, SyntaxError):
pass
return BridgeException(name, message, condition)
class SignalsHandler:
@ -996,7 +1009,9 @@ class TwistedBridge(bridge):
@param args(list): arguments
@param kwargs(dict): keyword arguments (profile, etc.)
"""
return super().call(name, *args, **kwargs)
d = super().call(name, *args, **kwargs)
d.addErrback(self._errback)
return d
async def bridge_connect(self) -> None:
"""Connect to the D-Bus bridge."""