{"record":{"id":"61d5451c40690fb5","repo":"sgl-project/sglang","slug":"image-file-not-found-image-path","errorCode":null,"errorMessage":"Image file not found: {image_path}","messagePattern":"Image file not found: (.+?)","errorType":"validation","errorClass":"FileNotFoundError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/apps/ComfyUI_SGLDiffusion/core/server_api.py","lineNumber":140,"sourceCode":"        common_params = self._build_image_common_params(\n            prompt=prompt,\n            size=size,\n            n=n,\n            response_format=response_format,\n            negative_prompt=negative_prompt,\n            guidance_scale=guidance_scale,\n            num_inference_steps=num_inference_steps,\n            seed=seed,\n            enable_teacache=enable_teacache,\n            background=background,\n            output_format=output_format,\n            generator_device=generator_device,\n        )\n\n        # If image_path is provided, use edit endpoint\n        if image_path:\n            if not os.path.exists(image_path):\n                raise FileNotFoundError(f\"Image file not found: {image_path}\")\n\n            # Prepare multipart form data for edit\n            files: Dict[str, Any] = {}\n            data = common_params.copy()\n\n            # Add image file\n            files[\"image\"] = (\n                os.path.basename(image_path),\n                open(image_path, \"rb\"),\n                self._get_content_type(image_path),\n            )\n\n            # Add mask file if provided\n            if mask_path:\n                if not os.path.exists(mask_path):\n                    raise FileNotFoundError(f\"Mask file not found: {mask_path}\")\n                files[\"mask\"] = (\n                    os.path.basename(mask_path),","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/apps/ComfyUI_SGLDiffusion/core/server_api.py#L122-L158","documentation":"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.","triggerScenarios":"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.","commonSituations":"Relative paths breaking when the script runs from another directory, upstream download/save step failed silently, container volume mounts omitting the file.","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"],"exampleFix":"# before\nclient.generate_image(prompt, image_path=\"imgs/input.png\")\n\n# after\nimage_path = os.path.abspath(\"imgs/input.png\")\nassert os.path.exists(image_path), image_path\nclient.generate_image(prompt, image_path=image_path)","handlingStrategy":"validation","validationCode":"import os\nimage_path = os.path.abspath(image_path)\nif image_path and not os.path.exists(image_path):\n    raise FileNotFoundError(image_path)","typeGuard":"def existing_file(p: str | None) -> bool:\n    return p is None or (os.path.isabs(p) and os.path.isfile(p))","tryCatchPattern":"try:\n    client.generate_image(prompt, image_path=image_path)\nexcept FileNotFoundError as e:\n    log.warning(f\"missing input image {e.filename}; skipping\")","preventionTips":["Normalize to absolute paths at the edge of the app","Verify artifacts from upstream steps exist before edit calls"],"tags":["file-io","image-edit","path-validation"],"backgroundTag":"file-not-found","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}