{"record":{"id":"02b6073f031a1026","repo":"sgl-project/sglang","slug":"mask-file-not-found-mask-path","errorCode":null,"errorMessage":"Mask file not found: {mask_path}","messagePattern":"Mask file not found: (.+?)","errorType":"validation","errorClass":"FileNotFoundError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/apps/ComfyUI_SGLDiffusion/core/server_api.py","lineNumber":156,"sourceCode":"        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),\n                    open(mask_path, \"rb\"),\n                    self._get_content_type(mask_path),\n                )\n\n            # Prepare headers for multipart form data\n            headers = {\n                \"Authorization\": f\"Bearer {self.api_key}\",\n            }\n\n            try:\n                response = requests.post(\n                    f\"{self.base_url}/images/edits\",\n                    files=files,\n                    data=data,\n                    headers=headers,\n                    timeout=300,  # 5 minutes timeout for generation","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/apps/ComfyUI_SGLDiffusion/core/server_api.py#L138-L174","documentation":"In edit mode with an optional mask, generate_image verifies the mask file exists before adding it to the multipart upload, raising FileNotFoundError with the given mask path. It mirrors the image_path check and fires only when a mask is actually supplied.","triggerScenarios":"Calling generate_image(..., image_path=valid, mask_path=m) where m doesn't exist — typo, wrong extension, or mask generated later by an external tool that hasn't run yet.","commonSituations":"Mask produced by an inpainting UI or preprocessing script that failed or wrote to a different location; mismatched .png/.jpg extensions.","solutions":["Verify or create the mask first; use absolute paths","Skip the mask entirely if you want unmasked editing rather than passing a bad path","Check the mask-generation step's output location and pass that path"],"exampleFix":"# before\nclient.generate_image(prompt, image_path=img, mask_path=\"mask.png\")\n\n# after\nmask_path = os.path.abspath(\"masks/mask.png\")\nif not os.path.exists(mask_path):\n    mask_path = None  # or generate the mask first\nclient.generate_image(prompt, image_path=img, mask_path=mask_path)","handlingStrategy":"validation","validationCode":"import os\nif mask_path:\n    mask_path = os.path.abspath(mask_path)\n    if not os.path.isfile(mask_path):\n        mask_path = None  # degrade to unmasked edit, or raise","typeGuard":"def existing_mask(p: str | None) -> bool:\n    return p is None or os.path.isfile(p)","tryCatchPattern":"try:\n    client.generate_image(prompt, image_path=img, mask_path=mask_path)\nexcept FileNotFoundError as e:\n    if \"Mask file\" in str(e):\n        client.generate_image(prompt, image_path=img)  # retry without mask\n    else:\n        raise","preventionTips":["Run mask generation before edit requests","Treat mask_path as optional and validate with os.path.isfile"],"tags":["file-io","mask","inpainting","path-validation"],"backgroundTag":"file-not-found","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}