Skip to content

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

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

fix(letters): add missing error logging to /api/letters/{id}/extract#16
aircode610 wants to merge 1 commit into
mainfrom
fix/issue-8-extract-endpoint-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 errors — the comment misleadingly claimed they 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 logging import + logger = logging.getLogger("klar.letters") to letters.py
  • Added logger.exception() to the generic except Exception handler and logger.info() to the typed PdfRenderError/ExtractionError handlers — matching what public.py already does
  • Added 3 new regression tests covering the /api/letters/{id}/extract path (scanned PDF → EXTRACTION_FAILED, corrupt PDF → PDF_RENDER_FAILED, unexpected error → generic 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 silently swallowed errors — the
comment claimed they were "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 what public.py already does. Added 3 regression tests
covering this endpoint path.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

@aircode610 aircode610 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 TODO / FIXME Scan

I checked every added and modified line in this PR for TODO, FIXME, HACK, and XXX comments.

Result: ✅ No TODO or FIXME comments found.

The PR is clean — no deferred-work markers were introduced in either backend/app/routers/letters.py or backend/tests/test_scanned_pdf_graceful.py.

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