{"record":{"id":"cce2d1371b08baff","repo":"PaddlePaddle/PaddleOCR","slug":"file-not-found-file-path-cce2d1","errorCode":null,"errorMessage":"File not found: {file_path}","messagePattern":"File not found: (.+?)","errorType":"exception","errorClass":"FileNotFoundError","httpStatus":null,"severity":"error","filePath":"paddleocr/_doc2md/core.py","lineNumber":49,"sourceCode":"    Convert an office document to Markdown.\n\n    Args:\n        source: Path to the source file.\n        output: Optional output file path. If provided, Markdown is written there.\n        **kwargs: Extra arguments forwarded to the specific converter.\n\n    Returns:\n        ConvertResult object.\n\n    Examples:\n        >>> from paddleocr import doc2md_convert\n        >>> result = doc2md_convert(\"report.docx\")\n        >>> print(result.markdown)\n    \"\"\"\n    file_path = Path(source)\n\n    if not file_path.exists():\n        raise FileNotFoundError(f\"File not found: {file_path}\")\n\n    converter = default_registry.get_converter(file_path)\n\n    try:\n        result = converter.convert_file(file_path, **kwargs)\n    except Exception as e:\n        if isinstance(e, (FileNotFoundError, ValueError, RuntimeError)):\n            raise\n        raise RuntimeError(f\"Failed to convert {file_path.name}: {e}\") from e\n\n    if output:\n        output_path = Path(output)\n        output_path.parent.mkdir(parents=True, exist_ok=True)\n        output_path.write_text(result.markdown, encoding=\"utf-8\")\n        if result.images:\n            images_dir = output_path.parent / \"images\"\n            images_dir.mkdir(exist_ok=True)\n            for rel_path, img_bytes in result.images.items():","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/PaddlePaddle/PaddleOCR/blob/2661c7c0ef5c613e8f93c6e93b2e052399f0f854/paddleocr/_doc2md/core.py#L31-L67","documentation":"FileNotFoundError raised by doc2md_convert when the source path does not exist on disk. The function converts the input to a Path and checks existence before selecting a converter, failing fast with the resolved path in the message.","triggerScenarios":"doc2md_convert('report.docx') where report.docx is not in the current working directory; passing a relative path when the process runs from another directory; typo'd or user-supplied filenames.","commonSituations":"Web uploads where the temp file was cleaned up or the path is outside the sandbox; CLI tools run from a different cwd; relative paths in scheduled jobs.","solutions":["Verify the path exists before calling: Path(source).is_file()","Use absolute paths built from a known base directory","Check cwd if using relative paths: print(Path(source).resolve())"],"exampleFix":"# before\nresult = doc2md_convert(user_supplied_path)\n# after\nsrc = Path(user_supplied_path).resolve()\nif not src.is_file():\n    raise FileNotFoundError(src)\nresult = doc2md_convert(src)","handlingStrategy":"validation","validationCode":"from pathlib import Path\n\nsrc = Path(source).expanduser().resolve()\nif not src.is_file():\n    raise FileNotFoundError(f'no such file: {src}')","typeGuard":null,"tryCatchPattern":"try:\n    result = doc2md_convert(src)\nexcept FileNotFoundError as e:\n    log.warning('input missing: %s', e)\n    skip_or_prompt_user()","preventionTips":["Always resolve() user-supplied paths before use","Validate existence at request intake, not deep in the pipeline","Handle ~ with expanduser() for CLI inputs"],"tags":["filesystem","doc2md","validation"],"backgroundTag":null,"analyzedSha":"2661c7c0ef5c613e8f93c6e93b2e052399f0f854","analyzedAt":"2026-08-14T20:17:30.180Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}