diff --git a/cvat/apps/engine/cache.py b/cvat/apps/engine/cache.py index b745c1b99dea..2e270bec760d 100644 --- a/cvat/apps/engine/cache.py +++ b/cvat/apps/engine/cache.py @@ -12,7 +12,6 @@ Mpeg4CompressedChunkWriter, ZipChunkWriter, ZipCompressedChunkWriter) from cvat.apps.engine.models import DataChoice, StorageChoice from cvat.apps.engine.prepare import PrepareInfo -from .log import slogger class CacheInteraction: def __init__(self): @@ -47,19 +46,16 @@ def prepare_chunk_buff(self, db_data, quality, chunk_number): StorageChoice.LOCAL: db_data.get_upload_dirname(), StorageChoice.SHARE: settings.SHARE_ROOT }[db_data.storage] - try: - if os.path.exists(db_data.get_meta_path()): - source_path = os.path.join(upload_dir, db_data.video.path) - meta = PrepareInfo(source_path=source_path, meta_path=db_data.get_meta_path()) - for frame in meta.decode_needed_frames(chunk_number, db_data): - images.append(frame) - writer.save_as_chunk([(image, source_path, None) for image in images], buff) - else: - with open(db_data.get_dummy_chunk_path(chunk_number), 'r') as dummy_file: - images = [os.path.join(upload_dir, line.strip()) for line in dummy_file] - writer.save_as_chunk([(image, image, None) for image in images], buff) - except FileNotFoundError as ex: - slogger.glob.exception(f"{ex.strerror} {ex.filename}") + if os.path.exists(db_data.get_meta_path()): + source_path = os.path.join(upload_dir, db_data.video.path) + meta = PrepareInfo(source_path=source_path, meta_path=db_data.get_meta_path()) + for frame in meta.decode_needed_frames(chunk_number, db_data): + images.append(frame) + writer.save_as_chunk([(image, source_path, None) for image in images], buff) + else: + with open(db_data.get_dummy_chunk_path(chunk_number), 'r') as dummy_file: + images = [os.path.join(upload_dir, line.strip()) for line in dummy_file] + writer.save_as_chunk([(image, image, None) for image in images], buff) buff.seek(0) return buff, mime_type diff --git a/cvat/apps/engine/views.py b/cvat/apps/engine/views.py index 8483d26ebeda..1e95841ad476 100644 --- a/cvat/apps/engine/views.py +++ b/cvat/apps/engine/views.py @@ -461,6 +461,10 @@ def data(self, request, pk): return Response(data='unknown data type {}.'.format(data_type), status=status.HTTP_400_BAD_REQUEST) except APIException as e: return Response(data=e.default_detail, status=e.status_code) + except FileNotFoundError as ex: + msg = f"{ex.strerror} {ex.filename}" + slogger.task[pk].error(msg, exc_info=True) + return Response(data=msg, status=status.HTTP_404_NOT_FOUND) except Exception as e: msg = 'cannot get requested data type: {}, number: {}, quality: {}'.format(data_type, data_id, data_quality) slogger.task[pk].error(msg, exc_info=True)