Classify FileNotFoundError as PermanentError instead of TransientError

FileNotFoundError is a subclass of OSError, so it was caught by the
broad timeout/io handler and classified as transient. A file deleted
between discovery and fetch would retry 5 times on a file that's
permanently gone, then DLQ with a confusing error message.

Add an explicit FileNotFoundError check before the OSError catch so
deleted files go straight to the DLQ.
This commit is contained in:
Chris McDonough 2026-06-01 07:32:09 -04:00
parent d5e5733f67
commit c9c48bc814
2 changed files with 12 additions and 0 deletions

View file

@ -57,6 +57,9 @@ def _classify(exc: BaseException) -> Exception:
# ProxyError — every transport-layer failure that's worth retrying.
return TransientError(f"network: {exc}")
if isinstance(exc, FileNotFoundError):
return PermanentError(f"file not found: {exc}")
if isinstance(exc, asyncio.TimeoutError | TimeoutError | OSError):
return TransientError(f"timeout/io: {exc}")

View file

@ -261,3 +261,12 @@ async def test_existing_permanent_error_passes_through_unchanged():
with pytest.raises(PermanentError) as excinfo:
await run_job(client, _job())
assert excinfo.value is sentinel
@pytest.mark.asyncio
async def test_file_not_found_classified_as_permanent():
"""A deleted file should go straight to the DLQ, not retry."""
client = _mock_client()
client.create_document_from_source.side_effect = FileNotFoundError("gone")
with pytest.raises(PermanentError, match="file not found"):
await run_job(client, _job())