sgl-project/sglang · error · FileNotFoundError
Image file not found: {image_path}
Error message
Image file not found: {image_path} What it means
When image_path is given, generate_image switches to the image-edit endpoint and first verifies the file exists on disk, raising FileNotFoundError with the path so you can see exactly which input is missing before any upload is attempted.
Source
Thrown at python/sglang/multimodal_gen/apps/ComfyUI_SGLDiffusion/core/server_api.py:140
common_params = self._build_image_common_params(
prompt=prompt,
size=size,
n=n,
response_format=response_format,
negative_prompt=negative_prompt,
guidance_scale=guidance_scale,
num_inference_steps=num_inference_steps,
seed=seed,
enable_teacache=enable_teacache,
background=background,
output_format=output_format,
generator_device=generator_device,
)
# If image_path is provided, use edit endpoint
if image_path:
if not os.path.exists(image_path):
raise FileNotFoundError(f"Image file not found: {image_path}")
# Prepare multipart form data for edit
files: Dict[str, Any] = {}
data = common_params.copy()
# Add image file
files["image"] = (
os.path.basename(image_path),
open(image_path, "rb"),
self._get_content_type(image_path),
)
# Add mask file if provided
if mask_path:
if not os.path.exists(mask_path):
raise FileNotFoundError(f"Mask file not found: {mask_path}")
files["mask"] = (
os.path.basename(mask_path),View on GitHub (pinned to 0132848349)
Solutions
- Use an absolute path: os.path.abspath(image_path)
- Verify existence before calling: os.path.exists(image_path)
- If the file comes from an earlier step, assert that step succeeded before editing
Example fix
# before
client.generate_image(prompt, image_path="imgs/input.png")
# after
image_path = os.path.abspath("imgs/input.png")
assert os.path.exists(image_path), image_path
client.generate_image(prompt, image_path=image_path) Defensive patterns
Strategy: validation
Validate before calling
import os
image_path = os.path.abspath(image_path)
if image_path and not os.path.exists(image_path):
raise FileNotFoundError(image_path) Type guard
def existing_file(p: str | None) -> bool:
return p is None or (os.path.isabs(p) and os.path.isfile(p)) Try / catch
try:
client.generate_image(prompt, image_path=image_path)
except FileNotFoundError as e:
log.warning(f"missing input image {e.filename}; skipping") Prevention
- Normalize to absolute paths at the edge of the app
- Verify artifacts from upstream steps exist before edit calls
When it happens
Trigger: Calling generate_image(..., image_path=p) where p does not exist on the client machine: typo, relative path resolved from a different CWD, or file not yet written.
Common situations: Relative paths breaking when the script runs from another directory, upstream download/save step failed silently, container volume mounts omitting the file.
Understand the failure class
Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.
Related errors
- Mask file not found: {mask_path}
- Failed to edit image: {str(e)}
- Invalid expert_pack configuration:\n{details}
- Short read for {suffixed}
- Failed to load config from {file_path}: {str(e)}
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/61d5451c40690fb5.
Report an issue: GitHub.