fix: exception handler failure when exception is not DBusError (#215)

This commit is contained in:
J. Nick Koston 2023-08-01 10:00:46 -10:00 committed by GitHub
parent a311d3e9e4
commit d771bcf6a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -29,8 +29,10 @@ MESSAGE_TYPE_CALL = MessageType.METHOD_CALL
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)
@ -57,23 +59,21 @@ class SendReply:
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]],
@ -804,7 +804,7 @@ class BaseMessageBus:
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: