From b74dca780a310b85584f39909eb5b07cd854cecf Mon Sep 17 00:00:00 2001 From: Max Khon Date: Thu, 8 Aug 2019 14:10:14 +0700 Subject: [PATCH] SetHandler.network_commit(): Do not silently ignore all the exceptions: propagate errors from self.commit() (as ERROR_COMMITFAILED) properly. --- pyagentx/network.py | 6 +++++- pyagentx/sethandler.py | 10 +++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/pyagentx/network.py b/pyagentx/network.py index 9711398..e38fa29 100644 --- a/pyagentx/network.py +++ b/pyagentx/network.py @@ -222,7 +222,11 @@ def _start_network(self): elif request.type == pyagentx.AGENTX_COMMITSET_PDU: for handler in self._sethandlers.values(): - handler.network_commit(request.session_id, request.transaction_id) + try: + handler.network_commit(request.session_id, request.transaction_id) + except: + response.error = pyagentx.ERROR_COMMITFAILED + response.error_index = 1 logger.info("Received COMMITSET PDU") elif request.type == pyagentx.AGENTX_UNDOSET_PDU: diff --git a/pyagentx/sethandler.py b/pyagentx/sethandler.py index 30a2db5..618c438 100644 --- a/pyagentx/sethandler.py +++ b/pyagentx/sethandler.py @@ -33,11 +33,11 @@ def network_commit(self, session_id, transaction_id): tid = "%s_%s" % (session_id, transaction_id) try: oid, data = self.transactions[tid] - self.commit(oid, data) - if tid in self.transactions: - del(self.transactions[tid]) - except: - logger.error('CommitSet failed') + except KeyError: + return + self.commit(oid, data) + if tid in self.transactions: + del(self.transactions[tid]) def network_undo(self, session_id, transaction_id): tid = "%s_%s" % (session_id, transaction_id)