From 4f861155adcad90e3686ef117e0ab799fa0d78b3 Mon Sep 17 00:00:00 2001 From: Kevin Murphy Date: Thu, 19 Dec 2019 18:26:01 -0800 Subject: [PATCH] FileBundle: Pass responsibility for handling FileLoadError to caller --- ultratrace2/model/files/bundle.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/ultratrace2/model/files/bundle.py b/ultratrace2/model/files/bundle.py index e2a5f96..10216bf 100644 --- a/ultratrace2/model/files/bundle.py +++ b/ultratrace2/model/files/bundle.py @@ -8,6 +8,7 @@ ImageSetFileLoader, SoundFileLoader, FileLoaderBase, + FileLoadError, ) from .registry import get_loader_for @@ -114,13 +115,16 @@ def build_from_dir( if name not in bundles: bundles[name] = FileBundle(filepath) - loaded_file = file_loader(filepath) - if loaded_file is not None: - if isinstance(loaded_file, AlignmentFileLoader): - bundles[name].set_alignment_file(loaded_file) - elif isinstance(loaded_file, ImageSetFileLoader): - bundles[name].set_image_set_file(loaded_file) - elif isinstance(loaded_file, SoundFileLoader): - bundles[name].set_sound_file(loaded_file) + try: + loaded_file = file_loader.from_file(filepath) + if loaded_file is not None: + if isinstance(loaded_file, AlignmentFileLoader): + bundles[name].set_alignment_file(loaded_file) + elif isinstance(loaded_file, ImageSetFileLoader): + bundles[name].set_image_set_file(loaded_file) + elif isinstance(loaded_file, SoundFileLoader): + bundles[name].set_sound_file(loaded_file) + except FileLoadError as e: + logger.error(e) return cls(bundles)