diff mbox

Add filename output in case of json parse errors

Message ID 56D648D9.3050800@sonymobile.com (mailing list archive)
State New, archived
Headers show

Commit Message

Bird, Tim March 2, 2016, 1:58 a.m. UTC
Put the json.load() routines in a try/except clause, and
print out the file that failed to parse correctly.
I found this handy for debugging json errors in the test specs
and test plan files.
---
 engine/scripts/ovgen/ovgen.py | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
diff mbox

Patch

diff --git a/engine/scripts/ovgen/ovgen.py b/engine/scripts/ovgen/ovgen.py
index 7f14795..37a73b8 100755
--- a/engine/scripts/ovgen/ovgen.py
+++ b/engine/scripts/ovgen/ovgen.py
@@ -475,7 +475,13 @@  def parseGenTestPlan(tpFilePath, fout, fname, specs):
 
     with open(tpFilePath) as f:
         debug_print("parsing `%s' TP" % (tpFilePath), 1)
-        jd = json.load(f)
+	try:
+        	jd = json.load(f)
+	except:
+		print "Error parsing testplan file %s" % tpFilePath
+		f.seek(0)
+		js = json.load(f)
+
         name = jd["testPlanName"]
         fout.write("#testplan: %s\n" % (name))
         for t in jd["tests"]:
@@ -504,7 +510,13 @@  def parseSpec(specFileName):
     debug_print("Parsing %s spec file" % (specFileName))
 
     with open(specFileName) as f:
-        jd = json.load(f)
+	try:
+        	jd = json.load(f)
+	except:
+		print "Error parsing spec file %s" % specFileName
+		f.seek(0)
+		jd = json.load(f)
+		
         name = jd["testName"]
         debug_print("parsing `%s' spec" % (name), 1)