PaddlePaddle/PaddleOCR · error · SystemExit

error: {msg}

Error message

error: {msg}

What it means

Not an exception source itself but the shared `die()` helper in deploy/ios_demo/scripts/utils.py: it prints `error: <msg>` to stderr and raises SystemExit(1). Any script calling die() (e.g. bad CLI arguments, unreadable model paths) terminates through here with exit code 1.

Source

Thrown at deploy/ios_demo/scripts/utils.py:37

generic; the scripts resolve ``utils.py`` in this same ``scripts/`` directory first.
"""

from __future__ import annotations

import sys
from pathlib import Path
from typing import Any

__all__ = [
    "die",
    "user_input_names",
    "build_npy_dir_reader",
]


def die(msg: str) -> None:
    print(f"error: {msg}", file=sys.stderr)
    raise SystemExit(1)


def user_input_names(model_path: Path) -> list[str]:
    """Return non-initializer graph input names (user-visible inputs)."""
    import onnx

    m = onnx.load(str(model_path), load_external_data=True)
    init = {t.name for t in m.graph.initializer}
    return [i.name for i in m.graph.input if i.name not in init]


def build_npy_dir_reader(
    model_path: Path, data_dir: Path, *, max_samples: int | None = None
) -> Any:
    """ONNX Runtime ``CalibrationDataReader``: one float32 ``(NCHW)`` ``.npy`` per sample; sorted by filename.

    *model_path* is used to discover the single graph input name (``user_input_names``); it may be
    the original or an augmented model as long as the first user input is unchanged.

View on GitHub (pinned to 2661c7c0ef)

Solutions

  1. Read the message after `error:` — it states the failed precondition (usually a missing file or bad argument).
  2. Fix the named input: supply an existing ONNX model path or a directory of .npy files.
  3. In CI, treat exit code 1 with stderr starting `error:` as a usage/input problem, not a crash.
Defensive patterns

Strategy: validation

Validate before calling

from pathlib import Path

def inputs_valid(model_path: str, npy_dir: str) -> bool:
    return Path(model_path).is_file() and Path(npy_dir).is_dir()

Try / catch

try:
    main()
except SystemExit as e:
    if e.code == 1:
        # die() already printed 'error: <reason>' to stderr; treat as input error
        log.error("demo script aborted on invalid input; see stderr above")
    raise

Prevention

When it happens

Trigger: Caller invokes die() after a failed precondition: onnx model file missing, invalid npy input dir for build_npy_dir_reader, argument validation failure in the demo scripts.

Common situations: Shell/CI wrappers seeing exit code 1 with an `error:`-prefixed line; users expecting a traceback but getting a clean message because the scripts centralize fatal errors through die().

Related errors


AI-assisted analysis of PaddlePaddle/PaddleOCR@2661c7c0ef (2026-08-14). Data as JSON: /api/errors/87a34f5bf0a053f1. Report an issue: GitHub.