From 9ff123bed3c2733e6a0fbdf1b8b0352b9577d5a7 Mon Sep 17 00:00:00 2001 From: Daniel Salzman <daniel.salzman@nic.cz> Date: Mon, 9 Jan 2017 13:46:00 +0100 Subject: [PATCH] python/control: fix incomplete block read if error --- python/libknot/control.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/python/libknot/control.py b/python/libknot/control.py index f887c8df29..1849da3071 100755 --- a/python/libknot/control.py +++ b/python/libknot/control.py @@ -360,6 +360,7 @@ class KnotCtl(object): """ out = dict() + err_reply = None while True: reply = KnotCtlData() @@ -371,10 +372,14 @@ class KnotCtl(object): # Check for an error. if reply[KnotCtlDataIdx.ERROR]: - raise KnotCtlError(reply[KnotCtlDataIdx.ERROR], reply) + err_reply = reply + continue self._receive_stats(out, reply) + if err_reply: + raise KnotCtlError(err_reply[KnotCtlDataIdx.ERROR], err_reply) + return out def receive_block(self): @@ -384,17 +389,20 @@ class KnotCtl(object): """ out = dict() + err_reply = None while True: reply = KnotCtlData() reply_type = self.receive(reply) + # Stop if not data type. if reply_type not in [KnotCtlType.DATA, KnotCtlType.EXTRA]: break # Check for an error. if reply[KnotCtlDataIdx.ERROR]: - raise KnotCtlError(reply[KnotCtlDataIdx.ERROR], reply) + err_reply = reply + continue # Check for config data. if reply[KnotCtlDataIdx.SECTION]: @@ -408,4 +416,7 @@ class KnotCtl(object): else: continue + if err_reply: + raise KnotCtlError(err_reply[KnotCtlDataIdx.ERROR], err_reply) + return out -- GitLab