{"record":{"id":"6dd99143c8851d9f","repo":"PrefectHQ/fastmcp","slug":"no-image-data-available","errorCode":null,"errorMessage":"No image data available","messagePattern":"No image data available","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"fastmcp_slim/fastmcp/utilities/types.py","lineNumber":291,"sourceCode":"\n        if self.path:\n            # Workaround for WEBP in Py3.10\n            mimetypes.add_type(\"image/webp\", \".webp\")\n            resp = mimetypes.guess_type(self.path, strict=False)\n            if resp and resp[0] is not None:\n                return resp[0]\n            return \"application/octet-stream\"\n        return \"image/png\"  # default for raw binary data\n\n    def _get_data(self) -> str:\n        \"\"\"Get raw image data as base64-encoded string.\"\"\"\n        if self.path:\n            with open(self.path, \"rb\") as f:\n                data = base64.b64encode(f.read()).decode()\n        elif self.data is not None:\n            data = base64.b64encode(self.data).decode()\n        else:\n            raise ValueError(\"No image data available\")\n        return data\n\n    def to_image_content(\n        self,\n        mime_type: str | None = None,\n        annotations: Annotations | None = None,\n    ) -> mcp_types.ImageContent:\n        \"\"\"Convert to MCP ImageContent.\"\"\"\n        data = self._get_data()\n\n        return mcp_types.ImageContent(\n            type=\"image\",\n            data=data,\n            mime_type=mime_type or self._mime_type,\n            annotations=annotations or self.annotations,\n        )\n\n    def to_data_uri(self, mime_type: str | None = None) -> str:","sourceCodeStart":273,"sourceCodeEnd":309,"githubUrl":"https://github.com/PrefectHQ/fastmcp/blob/1f021142978e0861cd910c8df4e8074bc7cf3978/fastmcp_slim/fastmcp/utilities/types.py#L273-L309","documentation":"Image._get_data base64-encodes the image from its path or in-memory bytes. If both self.path and self.data are somehow empty at read time (the constructor normally prevents this, but direct instantiation via __new__/deserialization or a falsy path can bypass it), it raises ValueError('No image data available'). This means the object holds no usable image source.","triggerScenarios":"Calling to_image_content() or to_data_uri() on an Image whose path and data are both unset — typically an object created through bypassed validation, unpickled state, or path='' (falsy) with data=None.","commonSituations":"Deserializing/serializing Image objects where the path attribute was dropped; constructing with an empty-string path that passes neither-check loosely; mutating .path/.data after construction.","solutions":["Recreate the Image with a valid path or non-empty data","Check img.path / img.data before calling to_image_content/to_data_uri","Verify the path is a non-empty string and the file exists"],"exampleFix":"// before\nimg = Image(path='')  # falsy path, no data\ncontent = img.to_image_content()  # raises\n// after\nimg = Image(path='img.png')\ncontent = img.to_image_content()","handlingStrategy":"type-guard","validationCode":"def to_content(img: Image):\n    if not img.path and img.data is None:\n        raise ValueError(\"Image has no path or data; rebuild it\")\n    return img.to_image_content()","typeGuard":"def has_image_data(img: Image) -> bool:\n    return bool(img.path) or img.data is not None","tryCatchPattern":"try:\n    content = img.to_image_content()\nexcept ValueError:\n    content = None  # or rebuild the Image from the original source","preventionTips":["Keep a reference to the original path/bytes so the Image can be rebuilt","Avoid mutating .path/.data on an Image after construction","If serializing Images, persist data (bytes) rather than relying on a path","Check has_image_data(img) before conversion calls"],"tags":["image","state","valueerror"],"backgroundTag":"missing-required-argument","analyzedSha":"1f021142978e0861cd910c8df4e8074bc7cf3978","analyzedAt":"2026-08-29T14:31:16.082Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}