Improved error handling

This commit is contained in:
Mark Qvist 2022-05-17 13:25:00 +02:00
parent 323241a4b8
commit ece55d10d6
2 changed files with 17 additions and 8 deletions

View file

@ -339,15 +339,21 @@ class LXMessage:
RNS.log("Received delivery notification for "+str(self), RNS.LOG_DEBUG) RNS.log("Received delivery notification for "+str(self), RNS.LOG_DEBUG)
self.state = LXMessage.DELIVERED self.state = LXMessage.DELIVERED
if self.__delivery_callback != None: if self.__delivery_callback != None and callable(self.__delivery_callback):
self.__delivery_callback(self) try:
self.__delivery_callback(self)
except Exception as e:
RNS.log("An error occurred in the external delivery callback for "+str(message), RNS.LOG_ERROR)
def __mark_propagated(self, receipt = None): def __mark_propagated(self, receipt = None):
RNS.log("Received propagation success notification for "+str(self), RNS.LOG_DEBUG) RNS.log("Received propagation success notification for "+str(self), RNS.LOG_DEBUG)
self.state = LXMessage.SENT self.state = LXMessage.SENT
if self.__delivery_callback != None: if self.__delivery_callback != None and callable(self.__delivery_callback):
self.__delivery_callback(self) try:
self.__delivery_callback(self)
except Exception as e:
RNS.log("An error occurred in the external delivery callback for "+str(message), RNS.LOG_ERROR)
def __resource_concluded(self, resource): def __resource_concluded(self, resource):
if resource.status == RNS.Resource.COMPLETE: if resource.status == RNS.Resource.COMPLETE:
@ -1130,8 +1136,11 @@ class LXMRouter:
message.transport_encrypted = False message.transport_encrypted = False
message.transport_encryption = None message.transport_encryption = None
if self.__delivery_callback != None: if self.__delivery_callback != None and callable(self.__delivery_callback):
self.__delivery_callback(message) try:
self.__delivery_callback(message)
except Exception as e:
RNS.log("An error occurred in the external delivery callback for "+str(message), RNS.LOG_ERROR)
return True return True
@ -1593,7 +1602,7 @@ class LXMRouter:
self.failed_outbound.append(lxmessage) self.failed_outbound.append(lxmessage)
lxmessage.state = LXMessage.FAILED lxmessage.state = LXMessage.FAILED
if lxmessage.failed_callback != None: if lxmessage.failed_callback != None and callable(lxmessage.failed_callback):
lxmessage.failed_callback(lxmessage) lxmessage.failed_callback(lxmessage)
def process_outbound(self, sender = None): def process_outbound(self, sender = None):

View file

@ -18,6 +18,6 @@ setuptools.setup(
"License :: OSI Approved :: MIT License", "License :: OSI Approved :: MIT License",
"Operating System :: OS Independent", "Operating System :: OS Independent",
], ],
install_requires=['rns>=0.3.4'], install_requires=['rns>=0.3.6'],
python_requires='>=3.6', python_requires='>=3.6',
) )