calesthio/OpenMontage · error · FileNotFoundError
not found
Error message
{label} not found: {media_path} What it means
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.
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
Example fix
// before
b64 = file_to_raw_base64(media_path)
// after
from pathlib import Path
p = Path(media_path).resolve()
if not p.is_file():
raise FileNotFoundError(f'{p.name} missing — earlier stage failed to produce it?')
b64 = file_to_raw_base64(p, label='Audio') Defensive patterns
Strategy: validation
Validate before calling
from pathlib import Path
def media_file_ready(path: str) -> bool:
p = Path(path)
return p.is_file() and p.stat().st_size > 0 Try / catch
try:
b64 = file_to_raw_base64(path, label='Audio')
except FileNotFoundError as e:
raise RuntimeError(f'upstream stage did not produce media: {e}') from e Prevention
- 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)
When it happens
Trigger: 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.
Common situations: 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.
Related errors
AI-assisted analysis of calesthio/OpenMontage@95e1c3d0ab (2026-08-15).
Data as JSON: /api/errors/e6ef02eb0e26d6ed.
Report an issue: GitHub.
Appendix: source
Thrown at tools/_kling/media.py:36
return value.split(marker, 1)[1]
return value
def image_file_to_raw_base64(path: str | Path) -> str:
"""Read a local image file and return raw base64 without data URI prefix."""
image_path = Path(path)
if not image_path.is_file():
raise FileNotFoundError(f"Image not found: {image_path}")
return base64.b64encode(image_path.read_bytes()).decode("ascii")
def file_to_raw_base64(path: str | Path, *, label: str = "File") -> str:
"""Read a local media file and return raw base64 without a data URI prefix."""
media_path = Path(path)
if not media_path.is_file():
raise FileNotFoundError(f"{label} not found: {media_path}")
return base64.b64encode(media_path.read_bytes()).decode("ascii")
def normalize_image_input(url: str | None = None, path: str | Path | None = None) -> str | None:
"""Normalize a Kling image input to either URL or raw base64."""
if url:
return strip_data_uri_prefix(url)
if path:
return image_file_to_raw_base64(path)
return None
def normalize_media_input(
url: str | None = None,
path: str | Path | None = None,
value: str | None = None,
*,View on GitHub (pinned to 95e1c3d0ab)