{"record":{"id":"512d3fd79b088ec1","repo":"calesthio/OpenMontage","slug":"image-not-found-image-path","errorCode":null,"errorMessage":"Image not found: {image_path}","messagePattern":"Image not found: (.+?)","errorType":"exception","errorClass":"FileNotFoundError","httpStatus":null,"severity":"error","filePath":"tools/_kling/media.py","lineNumber":27,"sourceCode":"\n\ndef strip_data_uri_prefix(value: str | None) -> str | None:\n    \"\"\"Return raw base64/content by removing a data URI prefix if present.\"\"\"\n\n    if value is None:\n        return None\n    marker = \";base64,\"\n    if value.startswith(\"data:\") and marker in value:\n        return value.split(marker, 1)[1]\n    return value\n\n\ndef image_file_to_raw_base64(path: str | Path) -> str:\n    \"\"\"Read a local image file and return raw base64 without data URI prefix.\"\"\"\n\n    image_path = Path(path)\n    if not image_path.is_file():\n        raise FileNotFoundError(f\"Image not found: {image_path}\")\n    return base64.b64encode(image_path.read_bytes()).decode(\"ascii\")\n\n\ndef file_to_raw_base64(path: str | Path, *, label: str = \"File\") -> str:\n    \"\"\"Read a local media file and return raw base64 without a data URI prefix.\"\"\"\n\n    media_path = Path(path)\n    if not media_path.is_file():\n        raise FileNotFoundError(f\"{label} not found: {media_path}\")\n    return base64.b64encode(media_path.read_bytes()).decode(\"ascii\")\n\n\ndef normalize_image_input(url: str | None = None, path: str | Path | None = None) -> str | None:\n    \"\"\"Normalize a Kling image input to either URL or raw base64.\"\"\"\n\n    if url:\n        return strip_data_uri_prefix(url)\n    if path:","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/calesthio/OpenMontage/blob/95e1c3d0ab93482159818560f6a8c8e866b9139f/tools/_kling/media.py#L9-L45","documentation":"Standard FileNotFoundError raised by image_file_to_raw_base64() in tools/_kling/media.py when the given path does not exist as a regular file (is_file() is false for missing paths and for directories). The offending path is included in the message.","triggerScenarios":"Calling normalize_image_input(path=...) or any function that base64-encodes a local image with a wrong path, a relative path resolved against an unexpected working directory, a directory path, or a file that was moved/deleted after the path was captured.","commonSituations":"Relative paths ('assets/ref.png') run from a different cwd; typos or wrong extension (.jpg vs .png); temp files cleaned up before the call; passing a URL where a local path was expected.","solutions":["Check the path with Path(p).resolve() and confirm it exists from the process's actual cwd","Use absolute paths, e.g. build them from a known root: BASE_DIR / 'assets' / 'ref.png'","If you meant to pass a hosted image, use the url= parameter instead of path="],"exampleFix":"// before\nb64 = image_file_to_raw_base64('assets/ref.png')  # relative, wrong cwd\n\n// after\nfrom pathlib import Path\nimg = Path('assets/ref.png').resolve()\nif not img.is_file():\n    raise FileNotFoundError(f'expected reference image missing: {img}')\nb64 = image_file_to_raw_base64(img)","handlingStrategy":"validation","validationCode":"from pathlib import Path\n\ndef image_input_ready(path: str) -> bool:\n    p = Path(path)\n    return p.is_file() and p.stat().st_size > 0","typeGuard":null,"tryCatchPattern":"try:\n    b64 = image_file_to_raw_base64(path)\nexcept FileNotFoundError as e:\n    logger.error('reference image missing: %s', e)\n    raise","preventionTips":["Resolve paths to absolute before the API call: Path(p).resolve()","Validate image existence at pipeline preflight, before any cost is incurred","For hosted images use url=, not path="],"tags":["kling","media","file-not-found","local-file","path"],"backgroundTag":null,"analyzedSha":"95e1c3d0ab93482159818560f6a8c8e866b9139f","analyzedAt":"2026-08-15T06:31:20.014Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}