An empty json file in the wrong directory format crashes the editor
If a user adds an empty json file in the wrong directory structure using file manager or command line like following:
Usually this is the correct structure: prefix/dataformats///1.json Lets make a file directly in folder so we will have: prefix/dataformats//1.json
If the editor is already open it shows it in the list of the files without giving any warning to the user. But then if you open this new json file the editor will close and this error is shown in the log:
Traceback (most recent call last):
File "/remote/idiap.svm/user.active/zmostaani/experiments/beat/beat.editor/beat/editor/widgets/assetwidget.py", line 356, in loadAsset
self.watcher.addPath(self.current_asset.declaration_path)
File "/remote/idiap.svm/user.active/zmostaani/experiments/beat/beat.editor/beat/editor/backend/asset.py", line 208, in declaration_path
storage = self.type.storage(self.prefix, self.name)
File "/remote/idiap.svm/user.active/zmostaani/experiments/beat/beat.editor/src/beat.backend.python/beat/backend/python/dataformat.py", line 77, in __init__
raise RuntimeError("invalid dataformat name: `%s'" % name)
RuntimeError: invalid dataformat name: `zmostaani/1'
Aborted
Now if you try to run the editor again this will be the error:
Traceback (most recent call last):
File "/remote/idiap.svm/user.active/zmostaani/experiments/beat/beat.editor/beat/editor/widgets/dataformateditor.py", line 601, in <lambda>
lambda: self.dataformat_model.setPrefixPath(self.prefix_path)
File "/remote/idiap.svm/user.active/zmostaani/experiments/beat/beat.editor/beat/editor/backend/assetmodel.py", line 182, in setPrefixPath
self.reload()
File "/remote/idiap.svm/user.active/zmostaani/experiments/beat/beat.editor/beat/editor/backend/assetmodel.py", line 119, in reload
json_files = _find_json_files(asset_folder)
File "/remote/idiap.svm/user.active/zmostaani/experiments/beat/beat.editor/beat/editor/backend/assetmodel.py", line 70, in _find_json_files
asset_items = os.scandir(path)
NotADirectoryError: [Errno 20] Not a directory: '/remote/idiap.svm/user.active/zmostaani/experiments/beat/beat.zmostaani.prefix/prefix/dataformats/zmostaani/1.json'
Aborted
Even though users are not supposed to make such problematic files but they may by accident and just having log information might not be enough. see #232 (closed)