Skip to content

Commit

Permalink
fix: exception handler failure when exception is not DBusError (#215)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Aug 1, 2023
1 parent a311d3e commit d771bcf
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/dbus_fast/message_bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@
MESSAGE_TYPE_SIGNAL = MessageType.SIGNAL
NO_REPLY_EXPECTED_VALUE = MessageFlag.NO_REPLY_EXPECTED.value

_Message = Message

def _expects_reply(msg) -> bool:

def _expects_reply(msg: _Message) -> bool:
return not (msg.flags.value & NO_REPLY_EXPECTED_VALUE)


Expand All @@ -57,23 +59,21 @@ def _exit(
exc_value: Optional[Exception],
tb: Optional[TracebackType],
) -> bool:
if exc_type is None:
return False

if issubclass(exc_type, DBusError):
self(exc_value._as_message(self._msg)) # type: ignore[union-attr]
return True

if issubclass(exc_type, Exception):
self(
Message.new_error(
self._msg,
ErrorType.SERVICE_ERROR,
f"The service interface raised an error: {exc_value}.\n{traceback.format_tb(tb)}",
if exc_value:
if isinstance(exc_value, DBusError):
self(exc_value._as_message(self._msg))
else:
self(
Message.new_error(
self._msg,
ErrorType.SERVICE_ERROR,
f"The service interface raised an error: {exc_value}.\n{traceback.format_tb(tb)}",
)
)
)
return True

return False

def __exit__(
self,
exc_type: Optional[Type[Exception]],
Expand Down Expand Up @@ -804,7 +804,7 @@ def _check_method_return(
ErrorType.INTERNAL_ERROR, "invalid message type for method call", msg
)

def _process_message(self, msg) -> None:
def _process_message(self, msg: _Message) -> None:
handled = False
for user_handler in self._user_message_handlers:
try:
Expand Down

0 comments on commit d771bcf

Please sign in to comment.