Skip to content

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

Improve Office parse failure messages

jinzhenjdaf623dff0de
diff --git a/mineru/cli/commands/parse.py b/mineru/cli/commands/parse.py
index 0a471d53..8441bc08 100644
--- a/mineru/cli/commands/parse.py
+++ b/mineru/cli/commands/parse.py
@@ -251,9 +251,10 @@ def _parse(
if st == "failed":
failed = next((row for row in parse_rows if row.status == "failed"), None)
_record_parse_wait(client, wait_parse_ids, "failed", wait_started_at)
- error_code = failed.error_code if failed else "parse_failed"
+ error_code = (failed.error_code if failed else None) or "parse_failed"
+ error_msg = (failed.error_msg if failed else None) or "Parse failed."
error_param = "parse_server.remote.api_key" if error_code == "invalid_api_key" else None
- raise MineruError(error_code, failed.error_msg if failed else "", error_param)
+ raise MineruError(error_code, error_msg, error_param)
_record_parse_wait(client, wait_parse_ids, "timeout", wait_started_at)
timeout_error = MineruError("parse_wait_timeout", f"Parse did not finish within {wait} seconds.", "wait")
diff --git a/mineru/doclib/constants.py b/mineru/doclib/constants.py
index 58284bca..7b80aed2 100644
--- a/mineru/doclib/constants.py
+++ b/mineru/doclib/constants.py
@@ -12,6 +12,12 @@ OFFICE_EXTENSIONS: set[str] = {
"xlsx",
}
+LEGACY_OFFICE_EXTENSION_UPGRADES: dict[str, str] = {
+ "doc": "docx",
+ "ppt": "pptx",
+ "xls": "xlsx",
+}
+
IMAGE_EXTENSIONS: set[str] = {
"bmp",
"gif",
diff --git a/mineru/doclib/services/parse_svc.py b/mineru/doclib/services/parse_svc.py
index 26f82d94..843892ed 100644
--- a/mineru/doclib/services/parse_svc.py
+++ b/mineru/doclib/services/parse_svc.py
@@ -17,7 +17,13 @@ from ...errors import InvalidRequestError, MineruError
from ...parser.api_client import _V1APIError
from ...parser.base import ParseResult
from ...types import TIER_ORDER, PageInfo, Tier
-from ..constants import IMAGE_EXTENSIONS, PARSEABLE_EXTENSIONS, TEXT_EXTENSIONS, is_office_temp_lock_file
+from ..constants import (
+ IMAGE_EXTENSIONS,
+ LEGACY_OFFICE_EXTENSION_UPGRADES,
+ PARSEABLE_EXTENSIONS,
+ TEXT_EXTENSIONS,
+ is_office_temp_lock_file,
+)
from ..core.db import DatabaseManager
from ..core.file_io import FileStat, MetadataExtractionError, compute_sha256, extract_metadata, get_file_stat
from ..core.fts import FTSManager
@@ -662,7 +668,7 @@ class ParseService:
refreshed = await self.refresh_file(path, ensure_ingested=True, allow_images=True)
if refreshed.status == "unsupported":
ext = Path(path).suffix.lower() or Path(path).name
- raise InvalidRequestError("file_type_unsupported", f"File type is not supported for parsing: {ext}", "path")
+ raise InvalidRequestError("file_type_unsupported", _unsupported_file_type_message(ext), "path")
if refreshed.status in {"missing", "deleted", "unreachable"}:
raise InvalidRequestError("file_not_found", f"File {path} not found.", "path")
if refreshed.status == "error":
@@ -1526,3 +1532,12 @@ def _safe_filename(page_range: str, done_at: int) -> str:
def _file_type_from_ext(ext: str) -> str:
return DOC_TYPE_BY_EXT.get(ext, ext or "unknown")
+
+
+def _unsupported_file_type_message(ext_or_name: str) -> str:
+ ext = ext_or_name.lower().lstrip(".")
+ upgrade_ext = LEGACY_OFFICE_EXTENSION_UPGRADES.get(ext)
+ if upgrade_ext:
+ return f".{ext} files are not supported; please convert to .{upgrade_ext}."
+ display = ext_or_name if ext_or_name.startswith(".") else Path(ext_or_name).name
+ return f"File type is not supported for parsing: {display}"
diff --git a/tests/unittest/test_cli_next_command_design.py b/tests/unittest/test_cli_next_command_design.py
index 054f9c65..108914ae 100644
--- a/tests/unittest/test_cli_next_command_design.py
+++ b/tests/unittest/test_cli_next_command_design.py
@@ -753,6 +753,50 @@ def test_parse_wait_json_maps_invalid_api_key_param(monkeypatch: Any, tmp_path:
assert payload["error"]["param"] == "parse_server.remote.api_key"
+def test_parse_wait_json_handles_failed_row_without_error_details(monkeypatch: Any, tmp_path: Path) -> None:
+ source = tmp_path / "demo.docx"
+ source.write_bytes(b"office")
+ failed = ParseInfo(
+ id=3,
+ sha256="a" * 64,
+ short_id="aaaaaaa",
+ tier="flash",
+ page_range="1",
+ status="failed",
+ privacy="remote",
+ created_at=3,
+ updated_at=4,
+ )
+
+ class _Client:
+ def __init__(self, *, timeout: int) -> None:
+ assert timeout == 31
+
+ def ensure_parse(self, request: Any) -> ParseResponse:
+ return ParseResponse(
+ sha256="a" * 64,
+ tier="flash",
+ page_range="1",
+ status="pending",
+ wait_parse_ids=[3],
+ created_parse_ids=[3],
+ )
+
+ def list_parses(self, **kwargs: Any) -> ListParsesResponse:
+ return ListParsesResponse(parses=[failed], total=1, limit=50, offset=0)
+
+ monkeypatch.setattr(parse, "DoclibClient", _Client)
+ monkeypatch.setattr(parse.time, "sleep", lambda seconds: None)
+
+ result = runner.invoke(app, ["parse", str(source), "--remote", "--wait", "1", "--json"])
+
+ assert result.exit_code == 1
+ payload = json.loads(result.output)
+ assert payload["error"]["type"] == "engine_error"
+ assert payload["error"]["code"] == "parse_failed"
+ assert payload["error"]["message"] == "Parse failed."
+
+
def test_parse_verbose_json_writes_cache_hit_notice_to_stderr(monkeypatch: Any, tmp_path: Path) -> None:
source = tmp_path / "demo.pdf"
source.write_bytes(b"%PDF-1.7\n")
diff --git a/tests/unittest/test_doclib_cache_semantics.py b/tests/unittest/test_doclib_cache_semantics.py
index 9783a551..c17d6399 100644
--- a/tests/unittest/test_doclib_cache_semantics.py
+++ b/tests/unittest/test_doclib_cache_semantics.py
@@ -1126,6 +1126,39 @@ def test_request_parse_rejects_unsupported_file_type_before_parse_response(tmp_p
asyncio.run(_run())
+ ("ext", "target_ext"),
+ [
+ ("doc", "docx"),
+ ("ppt", "pptx"),
+ ("xls", "xlsx"),
+ ],
+)
+def test_request_parse_rejects_legacy_office_with_conversion_hint(tmp_path: Path, ext: str, target_ext: str) -> 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 / f"sample.{ext}"
+ source.write_bytes(b"office")
+
+ with pytest.raises(InvalidRequestError) as exc_info:
+ await service.request_parse(str(source), tier="flash")
+
+ assert exc_info.value.code == "file_type_unsupported"
+ assert exc_info.value.param == "path"
+ assert f".{ext} files are not supported" in exc_info.value.message
+ assert f".{target_ext}" in exc_info.value.message
+
+ asyncio.run(_run())
+
+
def test_request_parse_raises_ingest_failed_when_file_row_has_no_sha(tmp_path: Path) -> None:
async def _run() -> None:
db = DatabaseManager(str(tmp_path / "doclib.db"))