|
27 | 27 | DeepEvalBaseEmbeddingModel, |
28 | 28 | DeepEvalBaseLLM, |
29 | 29 | ) |
| 30 | +from deepeval.errors import DeepEvalError |
30 | 31 | from deepeval.utils import update_pbar, add_pbar, remove_pbars |
31 | 32 | from deepeval.config.settings import get_settings |
32 | 33 |
|
@@ -209,6 +210,7 @@ def generate_contexts( |
209 | 210 | update_pbar(progress, pbar_id, remove=False) |
210 | 211 |
|
211 | 212 | # process each doc end-to-end (sync), with per-doc error logging |
| 213 | + docs_with_errors: List[str] = [] |
212 | 214 | for path, chunker in source_file_to_chunker_map.items(): |
213 | 215 | collection = None |
214 | 216 | try: |
@@ -267,6 +269,7 @@ def generate_contexts( |
267 | 269 | source_files.extend([path] * len(ctxs_for_doc)) |
268 | 270 |
|
269 | 271 | except Exception as exc: |
| 272 | + docs_with_errors.append(path) |
270 | 273 | # record and continue with other docs |
271 | 274 | show_trace = bool(get_settings().DEEPEVAL_LOG_STACK_TRACES) |
272 | 275 | exc_info = ( |
@@ -306,6 +309,12 @@ def generate_contexts( |
306 | 309 | "Not enough chunks in smallest document", |
307 | 310 | ) |
308 | 311 |
|
| 312 | + if docs_with_errors and not contexts: |
| 313 | + raise DeepEvalError( |
| 314 | + f"Context generation failed for all {len(docs_with_errors)} " |
| 315 | + f"document(s). Check the logs above for per-document errors." |
| 316 | + ) |
| 317 | + |
309 | 318 | return contexts, source_files, scores |
310 | 319 |
|
311 | 320 | finally: |
@@ -432,8 +441,10 @@ async def pipeline(path: str, chunker: DocumentChunker): |
432 | 441 | results = await asyncio.gather(*tasks, return_exceptions=True) |
433 | 442 |
|
434 | 443 | # Collect results, surface any errors after cleanup |
| 444 | + docs_with_errors: List[str] = [] |
435 | 445 | for path, res in zip(paths, results): |
436 | 446 | if isinstance(res, Exception): |
| 447 | + docs_with_errors.append(path) |
437 | 448 | logger.error( |
438 | 449 | "Document pipeline failed for %s", |
439 | 450 | path, |
@@ -463,6 +474,12 @@ async def pipeline(path: str, chunker: DocumentChunker): |
463 | 474 | "Not enough chunks in smallest document", |
464 | 475 | ) |
465 | 476 |
|
| 477 | + if docs_with_errors and not contexts: |
| 478 | + raise DeepEvalError( |
| 479 | + f"Context generation failed for all {len(docs_with_errors)} " |
| 480 | + f"document(s). Check the logs above for per-document errors." |
| 481 | + ) |
| 482 | + |
466 | 483 | return contexts, source_files, scores |
467 | 484 |
|
468 | 485 | finally: |
|
0 commit comments