Skip to content

Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.

Preserve permission errors in show file

jinzhenjc99a5999f5ff
diff --git a/mineru/doclib/services/parse_svc.py b/mineru/doclib/services/parse_svc.py
index af1dbaa6..630b6805 100644
--- a/mineru/doclib/services/parse_svc.py
+++ b/mineru/doclib/services/parse_svc.py
@@ -81,6 +81,22 @@ class FileRefreshResult:
return self.file is not None and self.file.sha256 is None
+def _raise_refresh_error(refreshed: FileRefreshResult) -> None:
+ code = (
+ (refreshed.file.error_code if refreshed.file and refreshed.file.error_code else None)
+ or refreshed.error_code
+ or "ingest_failed"
+ )
+ message = (
+ (refreshed.file.error_msg if refreshed.file and refreshed.file.error_msg else None)
+ or refreshed.error_msg
+ or "File could not be ingested."
+ )
+ if code == "file_permission_denied":
+ raise InvalidRequestError(code, message, "path")
+ raise MineruError(code, message, "path")
+
+
# ── range helpers ──────────────────────────────────────────────────
@@ -436,6 +452,8 @@ class ParseService:
"""Synchronously discover and ingest a source path when needed."""
path = normalize_doclib_path(path)
refreshed = await self.refresh_file(path, watch_id=watch_id, ensure_ingested=True, allow_images=allow_images)
+ if refreshed.status == "error":
+ _raise_refresh_error(refreshed)
if refreshed.file is None or refreshed.status == "unsupported":
return None
return cast(FileRow | None, await self.db.fetchone("SELECT * FROM files WHERE path=?", (path,)))
@@ -685,19 +703,7 @@ class ParseService:
if refreshed.status in {"missing", "deleted", "unreachable"}:
raise InvalidRequestError("file_not_found", f"File {path} not found.", "path")
if refreshed.status == "error":
- code = (
- (refreshed.file.error_code if refreshed.file and refreshed.file.error_code else None)
- or refreshed.error_code
- or "ingest_failed"
- )
- message = (
- (refreshed.file.error_msg if refreshed.file and refreshed.file.error_msg else None)
- or refreshed.error_msg
- or "File could not be ingested."
- )
- if code == "file_permission_denied":
- raise InvalidRequestError(code, message, "path")
- raise MineruError(code, message, "path")
+ _raise_refresh_error(refreshed)
if refreshed.file is None:
raise MineruError("ingest_failed", "File could not be ingested.", "path")
diff --git a/tests/unittest/test_doclib_cache_semantics.py b/tests/unittest/test_doclib_cache_semantics.py
index 3bb7fd15..07237cc6 100644
--- a/tests/unittest/test_doclib_cache_semantics.py
+++ b/tests/unittest/test_doclib_cache_semantics.py
@@ -2923,6 +2923,36 @@ def test_get_file_by_path_missing_doclib_record_message_is_not_disk_file_not_fou
asyncio.run(_run())
+def test_get_file_by_path_maps_stat_permission_error_without_existing_file_row(
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
+) -> None:
+ async def _run() -> None:
+ db = DatabaseManager(str(tmp_path / "doclib.db"))
+ await db.initialize()
+ parse_svc = ParseService(
+ db=db, fts=FTSManager(db), config_svc=None, data_dir=str(tmp_path / "data"), parse_lock_timeout_sec=1800
+ )
+ server = DoclibServer(SimpleNamespace(db=db, parse_svc=parse_svc))
+ source = tmp_path / "no_exec_dir" / "inside.pdf"
+
+ async def _permission_denied(path: str) -> dict[str, Any]:
+ raise PermissionError(f"permission denied: {path}")
+
+ monkeypatch.setattr(parse_svc_module, "get_file_stat", _permission_denied)
+
+ try:
+ with pytest.raises(InvalidRequestError) as exc_info:
+ await server.get_file_by_path(str(source))
+
+ assert exc_info.value.code == "file_permission_denied"
+ assert exc_info.value.param == "path"
+ assert str(source) in exc_info.value.message
+ finally:
+ await db.close()
+
+ asyncio.run(_run())
+
+
def test_scan_service_cleanup_keeps_latest_terminal_scans_and_active_tasks(tmp_path: Path) -> None:
async def _run() -> None:
db = DatabaseManager(str(tmp_path / "doclib.db"))