Skip to contentSkip to conversation

master - lvmdbusd: Bubble up invalid JSON

PATCH tasleson 1 participant 1 message Nov 17, 2016

lore
Share & tools
lore

tasleson

author
#0 lore raw
Gitweb:        http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=a1805cf336fc6608b71c9e74d9f072deb18582be
Commit:        a1805cf336fc6608b71c9e74d9f072deb18582be
Parent:        61f6be7d2b56177df4a855c048a954ced055ab0a
Author:        Tony Asleson <[email protected]>
AuthorDate:    Wed Nov 16 15:45:05 2016 -0600
Committer:     Tony Asleson <[email protected]>
CommitterDate: Thu Nov 17 11:35:16 2016 -0600

lvmdbusd: Bubble up invalid JSON

If we get invalid JSON, lets bubble that up to the user.

---
 daemons/lvmdbusd/lvm_shell_proxy.py |   20 ++++++++++++++------
 1 files changed, 14 insertions(+), 6 deletions(-)
daemons/lvmdbusd/lvm_shell_proxy.py +14 -6
index 9edf336..4cdb717 100755
@@ -202,12 +202,20 @@ class LVMShellProxy(object):
 
 		# Parse the report to see what happened
 		if report and len(report):
-			json_result = json.loads(report)
-			if 'log' in json_result:
-				if json_result['log'][-1:][0]['log_ret_code'] == '1':
-					rc = 0
-				else:
-					error_msg = self.get_error_msg()
+			try:
+				json_result = json.loads(report)
+				if 'log' in json_result:
+					if json_result['log'][-1:][0]['log_ret_code'] == '1':
+						rc = 0
+					else:
+						error_msg = self.get_error_msg()
+			except ValueError:
+				# The json is bad?, lets dump out for debug
+				with open('/tmp/json_bad', 'w') as debug:
+					debug.write(report)
+
+				# Bubble up the invalid json.
+				error_msg = "Invalid json %s" % report
 
 		if debug or rc != 0:
 			log_error(('CMD: %s' % cmd))