Title: Narrow except Exception in extractor.py:96 to specific PDF error
Body:
Problem
In diffiq/extractor.py, line 96 catches Exception broadly:
try:
reader = pypdf.PdfReader(io.BytesIO(raw_bytes))
pages: list[str] = []
for page in reader.pages:
text = page.extract_text()
if text:
pages.append(text)
except Exception as e:
logger.warning("pypdf extraction failed for %s: %s", pdf_url, e)
return ExtractionResult(text=None, error=f"Corrupted PDF: {e}")
This catch is too broad — it would silently swallow KeyboardInterrupt, MemoryError, or any unexpected bug in the loop logic. The only expected failure here is a corrupted/invalid PDF, which pypdf raises as PdfReadError.
Solution
Replace except Exception with except pypdf.errors.PdfReadError:
except pypdf.errors.PdfReadError as e:
logger.warning("pypdf extraction failed for %s: %s", pdf_url, e)
return ExtractionResult(text=None, error=f"Corrupted PDF: {e}")
Acceptance Criteria
Difficulty
Easy — 1 exception type change, 1 file
Size
XS — 1 line
Files Affected
diffiq/extractor.py
Title: Narrow except Exception in extractor.py:96 to specific PDF error
Body:
Problem
In
diffiq/extractor.py, line 96 catchesExceptionbroadly:This catch is too broad — it would silently swallow
KeyboardInterrupt,MemoryError, or any unexpected bug in the loop logic. The only expected failure here is a corrupted/invalid PDF, whichpypdfraises asPdfReadError.Solution
Replace
except Exceptionwithexcept pypdf.errors.PdfReadError:Acceptance Criteria
Exceptionis no longer caught — onlypypdf.errors.PdfReadErrorpytest tests/ -vpassesDifficulty
Easy — 1 exception type change, 1 file
Size
XS — 1 line
Files Affected
diffiq/extractor.py