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
Improve parse error messages
jinzhenj916ea0ab4d24
diff --git a/mineru/cli/commands/parse.py b/mineru/cli/commands/parse.pyindex 15eaeba0..96b6311d 100644--- a/mineru/cli/commands/parse.py+++ b/mineru/cli/commands/parse.py@@ -274,10 +274,7 @@ def _output_parse_result(except typer.Exit:raiseexcept Exception as exc:- if json_mode:- exit_with_error(exc, json_mode=True)- print_error(f"Failed to read content: {exc}")- raise typer.Exit(1) from None+ exit_with_error(exc, json_mode=json_mode)def _fetch_doc_content(diff --git a/mineru/errors.py b/mineru/errors.pyindex 7e040fe9..f6b9f756 100644--- a/mineru/errors.py+++ b/mineru/errors.py@@ -118,6 +118,9 @@ class MineruError(Exception):self.param = paramself.type = error_type_for(code)+ def __str__(self) -> str:+ return self.message or self.code+class InvalidRequestError(MineruError):def __init__(self, code: str = "invalid_request", message: str = "", param: str | None = None) -> None:diff --git a/tests/unittest/test_cli_next_command_design.py b/tests/unittest/test_cli_next_command_design.pyindex 346dad2f..104f1b48 100644--- a/tests/unittest/test_cli_next_command_design.py+++ b/tests/unittest/test_cli_next_command_design.py@@ -915,6 +915,30 @@ def test_parse_content_read_failure_exits_nonzero(monkeypatch: Any, tmp_path: Paassert "Error:" not in result.output+def test_parse_content_read_failure_non_json_prints_message_not_error_tuple(monkeypatch: Any, tmp_path: Path) -> None:+ source = tmp_path / "demo.txt"+ source.write_text("hello", encoding="utf-8")++ class _Client:+ def __init__(self, *, timeout: int) -> None:+ assert timeout == 90++ def ensure_parse(self, request: Any) -> ParseResponse:+ assert request.path == str(source.resolve())+ return ParseResponse(sha256="a" * 64, tier="flash", page_range="all", status="done", cache_hit=True)++ def get_doc_content(self, *args: Any, **kwargs: Any) -> None:+ raise RuntimeError("('not_cached', 'Requested parsed content is not cached.', 'page_range')")++ monkeypatch.setattr(parse, "DoclibClient", _Client)++ result = runner.invoke(app, ["parse", str(source), "--tier", "flash"])++ assert result.exit_code == 1+ assert "Requested parsed content is not cached." in result.output+ assert "('not_cached'" not in result.output++def test_read_passes_locator_parameters_to_doclib_client(monkeypatch: Any) -> None:calls: list[tuple[str, dict[str, Any]]] = []diff --git a/tests/unittest/test_errors.py b/tests/unittest/test_errors.pyindex e67aece7..d3578a02 100644--- a/tests/unittest/test_errors.py+++ b/tests/unittest/test_errors.py@@ -1,6 +1,6 @@from __future__ import annotations-from mineru.errors import http_status_for, error_type_for, registered_error_codes+from mineru.errors import MineruError, http_status_for, error_type_for, registered_error_codesDOCLIB_PERSISTED_ERROR_CODES = {@@ -69,3 +69,10 @@ def test_http_status_for_error_codes_is_stable() -> None:assert http_status_for("engine_unavailable") == 503assert http_status_for("parse_server_unavailable") == 500assert http_status_for("internal_error") == 500+++def test_mineru_error_string_is_human_readable() -> None:+ assert str(MineruError("not_cached", "Requested parsed content is not cached.", "page_range")) == (+ "Requested parsed content is not cached."+ )+ assert str(MineruError("not_cached")) == "not_cached"