An empty json file in the correct directory structure crashes the editor
At the moment it is assumed the prefix is completely valid. If a user adds an empty json file (using file manager or command line for example $ touch 1.json) in the correct directory format, if the editor is open it is shown on the list of the available asset, without any error or warning. But is you click on it the editor will close completely and there is a log error.
Traceback (most recent call last):
File "/remote/idiap.svm/user.active/zmostaani/experiments/beat/beat.editor/beat/editor/widgets/assetwidget.py", line 358, in loadAsset
self.__update_content()
File "/remote/idiap.svm/user.active/zmostaani/experiments/beat/beat.editor/beat/editor/widgets/assetwidget.py", line 214, in __update_content
editor.load_json(json.loads(json_data))
File "/idiap/user/zmostaani/miniconda3/envs/beat2/lib/python3.6/site-packages/simplejson/__init__.py", line 518, in loads
return _default_decoder.decode(s)
File "/idiap/user/zmostaani/miniconda3/envs/beat2/lib/python3.6/site-packages/simplejson/decoder.py", line 370, in decode
obj, end = self.raw_decode(s)
File "/idiap/user/zmostaani/miniconda3/envs/beat2/lib/python3.6/site-packages/simplejson/decoder.py", line 400, in raw_decode
return self.scan_once(s, idx=_w(s, idx).end())
simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Aborted
After the editor crashes you can run it again. It will run containing the mistaken json file. Now assume you know where the problem is and this time you learnt your lesson and you want to use editor to delete the asset. Go to the file in question. Right click on it and choose delete. Again the editor crashes and this is in the log info:
Traceback (most recent call last):
File "/remote/idiap.svm/user.active/zmostaani/experiments/beat/beat.editor/beat/editor/widgets/assetwidget.py", line 321, in deleteAsset
if self.current_asset.declaration_path == file_path:
AttributeError: 'NoneType' object has no attribute 'declaration_path'
Aborted
You can only remove it now is to use file manager or command line again.
It would be good to handle such instances more gracefully and more informative for the user since it is not easy from this log to understand where the problem is unless the user remembers exactly what they have done to cause this problem. It is not always the case :D
Also if we have multiple instance of editor open from terminal (see #228) and lose this information completely it would be even worse.