Fixes to borg output processing after testing on a Linux system

Mon, 29 Jan 2018 14:17:03 +0000

author
Tuomo Valkonen <tuomov@iki.fi>
date
Mon, 29 Jan 2018 14:17:03 +0000
changeset 95
41bd7025532f
parent 94
2a11fd29c192
child 96
de8ac6c470d8

Fixes to borg output processing after testing on a Linux system

borgend/instance.py file | annotate | diff | comparison | revisions
--- a/borgend/instance.py	Mon Jan 29 14:02:55 2018 +0000
+++ b/borgend/instance.py	Mon Jan 29 14:17:03 2018 +0000
@@ -78,23 +78,27 @@
 
     def read_result(self):
         stream=self.proc.stdout
-        line=stream.read(-1)
+        try:
+            line=stream.read(-1)
+        except Exception:
+            logger.exception('Borg stdout pipe read failed')
+
         if line==b'':
-            logger.debug('Borg stdout pipe EOF?')
+            #logger.debug('Borg stdout pipe EOF?')
             return None
 
         try:
-            return json.loads(line)
-        except Exception as err:
-            logger.warning('JSON parse failed on: "%s"' % line)
+            return json.loads(line.decode())
+        except Exception:
+            logger.exception('JSON parse failed on: %s' % str(line))
             return None
 
     def read_log(self):
         stream=self.proc.stderr
         try:
             line=stream.readline()
-        except err:
-            logger.debug('Pipe read failed: %s' % str(err))
+        except Exception:
+            logger.exception('Pipe stderr pipe read failed')
 
             return {'type': 'log_message',
                     'levelname': 'CRITICAL',
@@ -103,18 +107,17 @@
                     'message': err}
 
         if line==b'':
-
-            logger.debug('Borg stderr pipe EOF?')
-
+            #logger.debug('Borg stderr pipe EOF?')
             return None
 
+
         try:
-            res=json.loads(line)
+            res=json.loads(line.decode())
             if 'type' not in res:
                 res['type']='UNKNOWN'
             return res
         except:
-            logger.debug('JSON parse failed on: "%s"' % str(line))
+            logger.exception('JSON parse failed on: %s' % str(line))
 
             errmsg=line
             for line in iter(stream.readline, b''):

mercurial