Skip to content

fix(letters): log extraction errors in /api/letters/{id}/extract#14

Open
aircode610 wants to merge 5 commits into
mainfrom
fix/issue-8-missing-extraction-logging
Open

fix(letters): log extraction errors in /api/letters/{id}/extract#14
aircode610 wants to merge 5 commits into
mainfrom
fix/issue-8-missing-extraction-logging

Conversation

@aircode610

Copy link
Copy Markdown
Owner

Summary

  • Fixes 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 — it raised KlarHTTPException (caught by klar_exception_handler) but never logged the original traceback. The old comment misleadingly claimed it would be "Logged by unhandled_exception_handler" — that handler is never reached.
  • Added logger.exception() to the generic handler and logger.info() to the typed PdfRenderError/ExtractionError handlers in letters.py, 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). 24/24 tests passing, ruff-clean.

Context

PR #13 fixed the core issue #8 crash across three entry points (POST /letters, SSE /process, sync /extract). The typed error handling was applied to all three, 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

  • All 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

aircode610 and others added 5 commits June 22, 2026 14:45
Adds a GitHub Actions workflow that triggers on issue creation and
automatically applies labels (type, component, priority, security)
and assigns team members based on keyword matching in the issue
title and body. Also creates 8 new repo labels for components,
priorities, and security.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The generic except handler in extract_letter silently swallowed exceptions:
it raised KlarHTTPException (caught by klar_exception_handler) but never
logged the original traceback. The misleading comment claimed the error
would be "Logged by unhandled_exception_handler" — but that handler is
never reached. This made production debugging impossible for extraction
failures on this endpoint.

Added logger.exception() to the generic handler and logger.info() to the
typed PdfRenderError/ExtractionError handlers, matching what public.py
already does. Also added 3 regression tests for the /api/letters/{id}/extract
path (24 total, all passing).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The CI workflow (lint.yml) was missing from this branch, so PR #14 had
zero status checks. Add it back with both the ruff lint job and a new
tests job that runs pytest against backend/tests/. Also fix a minor
ruff format violation in test_scanned_pdf_graceful.py.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The CI workflow was failing for two reasons:
1. pytest-asyncio was not installed, causing all 14 async tests to fail
   with "async def functions are not natively supported"
2. ruff found 22 lint errors (unused imports, f-strings without
   placeholders, E402 import ordering, unused variables) in the merged
   code (PR branch + main)

Adds pytest-asyncio to the CI install step, fixes all ruff lint errors
(removing unused imports/variables, reordering imports in public.py),
and applies ruff format across the codebase.

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