Skip to content

Commit

Permalink
config: Fix config checker for python 3.3/3.4
Browse files Browse the repository at this point in the history
Python 3.3 and 3.4 do not have a JSONDecodeError, therefore, we must
do by parsing the error message of the ValueError it throws instead.
  • Loading branch information
CounterPillow committed Mar 10, 2017
1 parent 7b8016f commit 5f41fef
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions cum/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,24 @@ def load(self):
else:
try:
j = json.load(f)
except json.decoder.JSONDecodeError as e:
except ValueError as e:
f.seek(0, 0)
raise exceptions.ConfigError(config=f.read(),
cursor=(e.lineno, e.colno),
message='Error reading config: {}'
.format(e.msg))
cfargs = {}
if hasattr(json.decoder, 'JSONDecodeError'):
cfargs = {'config': f.read(),
'cursor': (e.lineno, e.colno),
'message': 'Error reading config: {}'
.format(e.msg)}
else:
# Remove this hack when we drop Python 3.4 support
msg, pos = str(e).split(':')
m = re.match(r'\s*line (\d+) column (\d+).*', pos)
cur = (int(m.group(1)), int(m.group(2)))
cfargs = {'config': f.read(),
'cursor': cur,
'message': 'Error reading config: {}'
.format(msg)}
raise exceptions.ConfigError(**cfargs)
finally:
f.close()

Expand Down

0 comments on commit 5f41fef

Please sign in to comment.