{"record":{"id":"87a34f5bf0a053f1","repo":"PaddlePaddle/PaddleOCR","slug":"error-msg","errorCode":null,"errorMessage":"error: {msg}","messagePattern":"error: (.+?)","errorType":"console","errorClass":"SystemExit","httpStatus":null,"severity":"error","filePath":"deploy/ios_demo/scripts/utils.py","lineNumber":37,"sourceCode":"generic; the scripts resolve ``utils.py`` in this same ``scripts/`` directory first.\n\"\"\"\n\nfrom __future__ import annotations\n\nimport sys\nfrom pathlib import Path\nfrom typing import Any\n\n__all__ = [\n    \"die\",\n    \"user_input_names\",\n    \"build_npy_dir_reader\",\n]\n\n\ndef die(msg: str) -> None:\n    print(f\"error: {msg}\", file=sys.stderr)\n    raise SystemExit(1)\n\n\ndef user_input_names(model_path: Path) -> list[str]:\n    \"\"\"Return non-initializer graph input names (user-visible inputs).\"\"\"\n    import onnx\n\n    m = onnx.load(str(model_path), load_external_data=True)\n    init = {t.name for t in m.graph.initializer}\n    return [i.name for i in m.graph.input if i.name not in init]\n\n\ndef build_npy_dir_reader(\n    model_path: Path, data_dir: Path, *, max_samples: int | None = None\n) -> Any:\n    \"\"\"ONNX Runtime ``CalibrationDataReader``: one float32 ``(NCHW)`` ``.npy`` per sample; sorted by filename.\n\n    *model_path* is used to discover the single graph input name (``user_input_names``); it may be\n    the original or an augmented model as long as the first user input is unchanged.","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/PaddlePaddle/PaddleOCR/blob/2661c7c0ef5c613e8f93c6e93b2e052399f0f854/deploy/ios_demo/scripts/utils.py#L19-L55","documentation":"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.","triggerScenarios":"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.","commonSituations":"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().","solutions":["Read the message after `error:` — it states the failed precondition (usually a missing file or bad argument).","Fix the named input: supply an existing ONNX model path or a directory of .npy files.","In CI, treat exit code 1 with stderr starting `error:` as a usage/input problem, not a crash."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"from pathlib import Path\n\ndef inputs_valid(model_path: str, npy_dir: str) -> bool:\n    return Path(model_path).is_file() and Path(npy_dir).is_dir()","typeGuard":null,"tryCatchPattern":"try:\n    main()\nexcept SystemExit as e:\n    if e.code == 1:\n        # die() already printed 'error: <reason>' to stderr; treat as input error\n        log.error(\"demo script aborted on invalid input; see stderr above\")\n    raise","preventionTips":["Check file/dir arguments with Path.is_file()/is_dir() before invoking the demo scripts.","Treat exit code 1 plus an 'error:' stderr line as a usage problem, not a bug."],"tags":["python","cli","exit-code","ios-demo"],"backgroundTag":null,"analyzedSha":"2661c7c0ef5c613e8f93c6e93b2e052399f0f854","analyzedAt":"2026-08-14T20:17:30.180Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}