Fix: Not raising exception when the get_captions method fails - #192
Conversation
📝 WalkthroughWalkthroughThe change modifies error handling in the PDF marker component. It now constructs a result dictionary from keys and results, returns this mapping on successful captioning, and logs captioning errors while returning an empty dictionary instead of re-raising exceptions. Asyncio cancellation errors are still re-raised as before. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
openrag/components/indexer/loaders/pdf_loaders/marker.py (1)
262-266: Consider usingstrict=Trueinzip()and removing the assertion.The project requires Python 3.12+ (per
pyproject.toml), which fully supports thestrictparameter. The assertion at line 264 could raiseAssertionErrorif lengths mismatch, but this would be caught by the exception handler below (line 272-274) and silently return an empty dict. Usingzip(keys, results, strict=True)is more Pythonic and raisesValueErrorinstead, which is semantically more appropriate for a runtime data mismatch.Proposed refactor
try: results = await tqdm.gather(*tasks, desc="Captioning images") - assert len(keys) == len(results), "Mismatch between keys and results count" - result_dict = dict(zip(keys, results)) + result_dict = dict(zip(keys, results, strict=True)) return result_dict
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
openrag/components/indexer/loaders/pdf_loaders/marker.py
🧰 Additional context used
🪛 Ruff (0.14.10)
openrag/components/indexer/loaders/pdf_loaders/marker.py
265-265: zip() without an explicit strict= parameter
Add explicit value for parameter strict=
(B905)
266-266: Consider moving this statement to an else block
(TRY300)
🔇 Additional comments (1)
openrag/components/indexer/loaders/pdf_loaders/marker.py (1)
273-275: Approve the fault-tolerant error handling.The exception handler correctly logs failures and returns an empty dict, allowing PDF processing to continue when image captioning fails. The caller at lines 225-228 handles this gracefully by simply skipping the caption replacement loop when the dict is empty.
The design is intentional and appropriate for a non-critical feature. Note that
asyncio.CancelledErroris explicitly re-raised on line 267, showing deliberate distinction between cancellation (which should propagate) and other errors (which are absorbed).
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.