Skip to content

Commit 7857309

Browse files
committed
🥅(summary) catch unexpected file-related exceptions when handling recording objects
Previously, if a recording file was not found in the bucket, the code would crash. This adds proper error handling to avoid unhandled failures.
1 parent bb64532 commit 7857309

2 files changed

Lines changed: 45 additions & 28 deletions

File tree

‎src/summary/summary/core/celery_worker.py‎

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
from summary.core.analytics import MetadataManager, get_analytics
1818
from summary.core.config import get_settings
19-
from summary.core.file_service import FileService
19+
from summary.core.file_service import FileService, FileServiceException
2020
from summary.core.llm_service import LLMException, LLMObservability, LLMService
2121
from summary.core.prompt import (
2222
FORMAT_NEXT_STEPS,
@@ -145,36 +145,41 @@ def process_audio_transcribe_summarize_v2(
145145
max_retries=settings.whisperx_max_retries,
146146
)
147147

148-
with (
149-
file_service.prepare_audio_file(filename) as (audio_file, metadata),
150-
):
151-
metadata_manager.track(task_id, {"audio_length": metadata["duration"]})
152-
153-
if language is None:
154-
language = settings.whisperx_default_language
155-
logger.info(
156-
"No language specified, using default from settings: %s",
157-
(language or "auto-detect"),
158-
)
159-
else:
160-
logger.info(
161-
"Querying transcription in '%s' language",
162-
language,
148+
try:
149+
with (
150+
file_service.prepare_audio_file(filename) as (audio_file, metadata),
151+
):
152+
metadata_manager.track(task_id, {"audio_length": metadata["duration"]})
153+
154+
if language is None:
155+
language = settings.whisperx_default_language
156+
logger.info(
157+
"No language specified, using default from settings: %s",
158+
(language or "auto-detect"),
159+
)
160+
else:
161+
logger.info(
162+
"Querying transcription in '%s' language",
163+
language,
164+
)
165+
166+
transcription_start_time = time.time()
167+
168+
transcription = whisperx_client.audio.transcriptions.create(
169+
model=settings.whisperx_asr_model, file=audio_file, language=language
163170
)
164171

165-
transcription_start_time = time.time()
166-
167-
transcription = whisperx_client.audio.transcriptions.create(
168-
model=settings.whisperx_asr_model, file=audio_file, language=language
169-
)
172+
transcription_time = round(time.time() - transcription_start_time, 2)
173+
metadata_manager.track(
174+
task_id,
175+
{"transcription_time": transcription_time},
176+
)
177+
logger.info("Transcription received in %.2f seconds.", transcription_time)
178+
logger.debug("Transcription: \n %s", transcription)
170179

171-
transcription_time = round(time.time() - transcription_start_time, 2)
172-
metadata_manager.track(
173-
task_id,
174-
{"transcription_time": transcription_time},
175-
)
176-
logger.info("Transcription received in %.2f seconds.", transcription_time)
177-
logger.debug("Transcription: \n %s", transcription)
180+
except FileServiceException:
181+
logger.exception("Unexpected error for filename: %s", filename)
182+
return
178183

179184
metadata_manager.track_transcription_metadata(task_id, transcription)
180185

‎src/summary/summary/core/file_service.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,19 @@
88

99
import mutagen
1010
from minio import Minio
11+
from minio.error import MinioException, S3Error
1112

1213
from summary.core.config import get_settings
1314

1415
settings = get_settings()
1516

1617

18+
class FileServiceException(Exception):
19+
"""Base exception for file service operations."""
20+
21+
pass
22+
23+
1724
class FileService:
1825
"""Service for downloading and preparing files from MinIO storage."""
1926

@@ -79,6 +86,11 @@ def _download_from_minio(self, remote_object_key) -> Path:
7986

8087
return local_path
8188

89+
except (MinioException, S3Error) as e:
90+
raise FileServiceException(
91+
"Unexpected error while downloading object."
92+
) from e
93+
8294
finally:
8395
if response:
8496
response.close()

0 commit comments

Comments
 (0)