Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.
Python ai4sciencedocument-analysisdocxextract-datalayout-analysisocrparserpdfpdf-converterpdf-extractor-llmpdf-extractor-pretrainpdf-extractor-ragpdf-parserpptxpythonxlsx
Map ingest permission errors
jinzhenjb0f7d756be09
diff --git a/mineru/doclib/services/parse_svc.py b/mineru/doclib/services/parse_svc.pyindex 8fa8df1c..c10ff3c8 100644--- a/mineru/doclib/services/parse_svc.py+++ b/mineru/doclib/services/parse_svc.py@@ -430,6 +430,10 @@ class ParseService:status = "succeeded"try:return await self._ingest_file(path, watch_id=watch_id)+ except PermissionError as exc:+ status = "failed"+ await self._mark_file_error(path, "file_permission_denied", str(exc))+ raise InvalidRequestError("file_permission_denied", str(exc), "path") from Noneexcept Exception:status = "failed"raise@@ -438,6 +442,13 @@ class ParseService:await self._record_count("ingest.finished.count", dimensions=dimensions)await self._record_duration("ingest.duration_bucket.count", start_ms, dimensions=dimensions)+ async def _mark_file_error(self, path: str, error_code: str, error_msg: str) -> None:+ now = _now_ms()+ await self.db.execute(+ "UPDATE files SET sha256=NULL, locked_at=NULL, error_code=?, error_msg=?, updated_at=? WHERE path=?",+ (error_code, error_msg[:500], now, path),+ )+async def _ingest_file(self, path: str, watch_id: int | None = None) -> FileRow | None:"""Ingest implementation without telemetry wrapper."""ext = Path(path).suffix.lower().lstrip(".")diff --git a/tests/unittest/test_doclib_cache_semantics.py b/tests/unittest/test_doclib_cache_semantics.pyindex 439a6008..f74b501f 100644--- a/tests/unittest/test_doclib_cache_semantics.py+++ b/tests/unittest/test_doclib_cache_semantics.py@@ -1016,6 +1016,36 @@ def test_refresh_file_marks_missing_known_path_deleted(tmp_path: Path) -> None:asyncio.run(_run())+def test_ensure_ingested_maps_read_permission_error_to_file_permission_denied(+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch+) -> None:+ async def _run() -> None:+ db = DatabaseManager(str(tmp_path / "doclib.db"))+ await db.initialize()+ service = ParseService(db=db, fts=FTSManager(db), config_svc=None, data_dir=str(tmp_path / "data"), parse_lock_timeout_sec=1800)+ source = tmp_path / "locked.pdf"+ source.write_bytes(b"%PDF-1.7\n")++ async def _permission_denied(path: str) -> str:+ raise PermissionError("permission denied")++ monkeypatch.setattr(parse_svc_module, "compute_sha256", _permission_denied)++ with pytest.raises(InvalidRequestError) as exc_info:+ await service.ensure_ingested(str(source))++ row = await db.fetchone("SELECT sha256, error_code, error_msg FROM files WHERE path=?", (str(source),))++ assert exc_info.value.code == "file_permission_denied"+ assert exc_info.value.param == "path"+ assert row is not None+ assert row["sha256"] is None+ assert row["error_code"] == "file_permission_denied"+ assert row["error_msg"] == "permission denied"++ asyncio.run(_run())++def test_refresh_file_records_stat_error_without_marking_deleted(tmp_path: Path, monkeypatch) -> None:async def _run() -> None:db = DatabaseManager(str(tmp_path / "doclib.db"))