From 45488de06f8adc987fd453807177fb3c148f4346 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Fri, 4 May 2012 20:28:48 +0200 Subject: [PATCH] try to give context if jsonc parsing fails --- ox/jsonc.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ox/jsonc.py b/ox/jsonc.py index 9170d3c..0090244 100644 --- a/ox/jsonc.py +++ b/ox/jsonc.py @@ -11,5 +11,11 @@ def load(f): return loads(f.read()) def loads(source): - return json.loads(minify(source)) - + try: + minified = minify(source) + return json.loads(minified) + except json.JSONDecodeError, e: + s = minified.split('\n') + context = s[e.lineno-1][max(0, e.colno-1):e.colno+30] + msg = e.msg + ' at ' + context + raise json.JSONDecodeError(msg, minified, e.pos)