{"record":{"id":"e6ef02eb0e26d6ed","repo":"calesthio/OpenMontage","slug":"label-not-found-media-path","errorCode":null,"errorMessage":"{label} not found: {media_path}","messagePattern":"(.+?) not found: (.+?)","errorType":"exception","errorClass":"FileNotFoundError","httpStatus":null,"severity":"error","filePath":"tools/_kling/media.py","lineNumber":36,"sourceCode":"        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:\n        return image_file_to_raw_base64(path)\n    return None\n\n\ndef normalize_media_input(\n    url: str | None = None,\n    path: str | Path | None = None,\n    value: str | None = None,\n    *,","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/calesthio/OpenMontage/blob/95e1c3d0ab93482159818560f6a8c8e866b9139f/tools/_kling/media.py#L18-L54","documentation":"Generic FileNotFoundError raised by file_to_raw_base64() for any media file (audio/image/video) whose path is not an existing regular file. The label kwarg (default 'File') lets callers say 'Audio not found', 'Video not found', etc., making batch pipelines readable.","triggerScenarios":"Encoding a local audio or video file for a Kling request (lip-sync, video extension, audio-driven generation) with a missing/incorrect path; same causes as the image variant: wrong cwd for relative paths, directory passed instead of file, file deleted between listing and use.","commonSituations":"Pipeline stages that download or transcode media into temp dirs that get cleaned; user-supplied paths from a config/LLM that were never validated; extension mismatch.","solutions":["Validate the path early in the pipeline, before any API cost is incurred","Pass label= so the error names the media kind ('Audio', 'Video')","Re-check temp-file lifecycle if files disappear between stages; write to a stable work dir","Use absolute paths everywhere"],"exampleFix":"// before\nb64 = file_to_raw_base64(media_path)\n\n// after\nfrom pathlib import Path\np = Path(media_path).resolve()\nif not p.is_file():\n    raise FileNotFoundError(f'{p.name} missing — earlier stage failed to produce it?')\nb64 = file_to_raw_base64(p, label='Audio')","handlingStrategy":"validation","validationCode":"from pathlib import Path\n\ndef media_file_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 = file_to_raw_base64(path, label='Audio')\nexcept FileNotFoundError as e:\n    raise RuntimeError(f'upstream stage did not produce media: {e}') from e","preventionTips":["Validate media paths at preflight with the label set, so failures name the stage","Keep intermediate media in a stable work dir, not auto-cleaned temp dirs","Check the producing stage's output before encoding (size > 0, sane extension)"],"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-15T22:17:37.221Z"}