Skip to content

fix(letters): add missing error logging to /api/letters/{id}/extract#17

Open
aircode610 wants to merge 1 commit into
mainfrom
fix/issue-8-extract-logging
Open

fix(letters): add missing error logging to /api/letters/{id}/extract#17
aircode610 wants to merge 1 commit into
mainfrom
fix/issue-8-extract-logging

Conversation

@aircode610

Copy link
Copy Markdown
Owner

Summary

  • Closes a remaining gap from 500 error on /api/letters upload when PDF has no text layer #8: the /api/letters/{id}/extract endpoint's generic except Exception handler silently swallowed tracebacks — the comment misleadingly claimed errors would be "Logged by unhandled_exception_handler", but KlarHTTPException extends HTTPException which is caught by klar_exception_handler, so the original traceback was silently lost.
  • Added logger.exception() to the generic except Exception handler and logger.info() to the typed PdfRenderError/ExtractionError handlers in letters.py — matching the pattern public.py already uses.
  • Added 3 new regression tests covering the /api/letters/{id}/extract path (ExtractionError → 502 EXTRACTION_FAILED, PdfRenderError → 502 PDF_RENDER_FAILED, generic RuntimeError → 502 without leaking internals).

Context

PR #13 fixed the core issue #8 crash across all three entry points (POST /letters, SSE /process, sync /extract). The typed error handling was correctly applied everywhere, but logging was only added to public.py and orchestrator.py — the letters.py handler was left with a silent except Exception that makes production debugging impossible on the /api/letters/{id}/extract route.

Test plan

  • 24/24 regression tests pass (backend/tests/test_scanned_pdf_graceful.py)
  • ruff clean on both modified files
  • New tests cover: ExtractionError → 502 EXTRACTION_FAILED, PdfRenderError → 502 PDF_RENDER_FAILED, generic RuntimeError → 502 without leaking secrets

🤖 Generated with Claude Code

The generic `except Exception` handler in `extract_letter` silently
swallowed tracebacks — the comment claimed errors would be "Logged by
unhandled_exception_handler" but KlarHTTPException is caught by
klar_exception_handler instead, so the original traceback was lost.

Added `logger.exception()` to the generic handler and `logger.info()`
to the typed PdfRenderError/ExtractionError handlers, matching the
pattern already used in public.py. Includes 3 regression tests covering
the /api/letters/{id}/extract path (24/24 passing).

Closes #8

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant