Nasty error with malformed JSON
This is a similar issue than #9 (closed). If a malformed JSON is given as input, the user is exposed to the whole traceback resulting from the json.decoder.JSONDecodeError
that is raised. This should be handled gracefully.
Steps to reproduce:
echo '[[0, 0], [0, 1]' | cate - # missing closing bracket
The call then fails with the following trace:
Traceback (most recent call last):
File "/home/bleuse/devel/cate-dev.venv36/bin/cate", line 11, in <module>
load_entry_point('cate', 'console_scripts', 'cate')()
File "/home/bleuse/src/cate.git/src/cate/cli.py", line 107, in cli
main.run(matrix, **options)
File "/home/bleuse/src/cate.git/src/cate/main.py", line 349, in run
matrix = createMatrixfromFile(matrix)
File "/home/bleuse/src/cate.git/src/cate/main.py", line 35, in createMatrixfromFile
matrix = json.load(f)
File "/usr/lib/python3.6/json/__init__.py", line 299, in load
parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
File "/usr/lib/python3.6/json/__init__.py", line 354, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.6/json/decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.6/json/decoder.py", line 355, in raw_decode
obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting ',' delimiter: line 2 column 1 (char 16)