{"record":{"id":"5b064e6f7f74e861","repo":"bevyengine/bevy","slug":"invalid-image-mime-type-0-5b064e","errorCode":null,"errorMessage":"invalid image mime type: {0}","messagePattern":"invalid image mime type: (.+?)","errorType":"exception","errorClass":"TextureError","httpStatus":null,"severity":"error","filePath":"crates/bevy_image/src/image.rs","lineNumber":2290,"sourceCode":"    /// Image MIME type is invalid.\n    #[error(\"invalid image mime type: {0}\")]\n    InvalidImageMimeType(String),\n    /// Image extension is invalid.\n    #[error(\"invalid image extension: {0}\")]\n    InvalidImageExtension(String),\n    /// Failed to load an image.\n    #[error(\"failed to load an image: {0}\")]\n    ImageError(#[from] image::ImageError),\n    /// Texture format isn't supported.\n    #[error(\"unsupported texture format: {0}\")]\n    UnsupportedTextureFormat(String),\n    /// Supercompression isn't supported.\n    #[error(\"supercompression not supported: {0}\")]\n    SuperCompressionNotSupported(String),\n    /// Failed to decompress an image.\n    #[error(\"failed to decompress an image: {0}\")]\n    SuperDecompressionError(String),\n    /// Invalid data.\n    #[error(\"invalid data: {0}\")]\n    InvalidData(String),\n    /// Transcode error.\n    #[error(\"transcode error: {0}\")]\n    TranscodeError(String),\n    /// Format requires transcoding.\n    #[error(\"format requires transcoding: {0:?}\")]\n    FormatRequiresTranscodingError(TranscodeFormat),\n    /// Only cubemaps with six faces are supported.\n    #[error(\"only cubemaps with six faces are supported\")]\n    IncompleteCubemap,\n}\n\n/// The type of a raw image buffer.\n#[derive(Debug)]\npub enum ImageType<'a> {\n    /// The mime type of an image, for example `\"image/png\"`.\n    MimeType(&'a str),","sourceCodeStart":2272,"sourceCodeEnd":2308,"githubUrl":"https://github.com/bevyengine/bevy/blob/221e52ae323febfd399bd7d067918fc43648cfb3/crates/bevy_image/src/image.rs#L2272-L2308","documentation":"TextureError::InvalidImageMimeType is returned by ImageType::to_image_format (crates/bevy_image/src/image.rs:2333-2334) when ImageFormat::from_mime_type cannot map the string to a known format. from_mime_type (image.rs:451) only recognizes a fixed list (image/png, image/jpeg, image/vnd-ms.dds, image/ktx2, image/x-exr, ...) and each entry is feature-gated via the feature_gate! macro, so the mime may be unknown or its format's cargo feature may be disabled. Bevy throws it because it cannot pick a decoder for the bytes.","triggerScenarios":"Calling Image::from_buffer with ImageType::MimeType(\"image/tiff\") when bevy_image's tiff feature is off, or any unrecognized mime like \"image/avif\"; feeding a content-type header from a network download straight into ImageType::MimeType.","commonSituations":"Downloading images at runtime and passing the HTTP Content-Type as the image type; builds that trimmed bevy's default features (only png/qoi variants enabled) but still receive jpeg/webp mimes; typos like \"image/jpg\" (the canonical string is \"image/jpeg\").","solutions":["Pass ImageType::Format(ImageFormat::Png) (or whichever format the bytes really are) instead of a mime string — it bypasses the mapping entirely.","Pre-check with ImageFormat::from_mime_type(mime).is_some() and fall back to sniffing bytes via image::guess_format.","Enable the matching cargo feature on bevy/bevy_image (tiff, webp, bmp, exr, hdr, dds, ktx2, basis-universal, ...).","Fix the mime string to the canonical form (image/jpeg not image/jpg; image/vnd-ms.dds not image/dds)."],"exampleFix":"// before\nlet image = Image::from_buffer(&bytes, ImageType::MimeType(\"image/jpg\"), ...); // Err(InvalidImageMimeType)\n\n// after — be explicit about the format instead of the mime\nlet image = Image::from_buffer(&bytes, ImageType::Format(ImageFormat::Jpeg), ...);","handlingStrategy":"validation","validationCode":"// resolve the mime to a concrete format before building ImageType\nlet fmt = ImageFormat::from_mime_type(mime)\n    .unwrap_or_else(|| sniff_or_default(&bytes));\nlet image = Image::from_buffer(&bytes, ImageType::Format(fmt), formats, true, sampler, usage)?;","typeGuard":"fn mime_supported(mime: &str) -> bool {\n    ImageFormat::from_mime_type(mime).is_some()\n}","tryCatchPattern":"match Image::from_buffer(&bytes, ImageType::MimeType(mime), formats, true, sampler, usage) {\n    Err(TextureError::InvalidImageMimeType(bad)) => {\n        warn!(\"unknown mime {bad:?}; falling back to format sniffing\");\n        let fmt = image::guess_format(&bytes).ok().and_then(ImageFormat::from_image_crate_format);\n        // retry with ImageType::Format(fmt) ...\n    }\n    result => result?,\n}","preventionTips":["Prefer ImageType::Format over MimeType whenever you know the real format.","Keep a unit test mapping every mime string your app produces to an ImageFormat.","Enable cargo features for every format family your content pipeline emits."],"tags":["bevy","image","mime-type","feature-gate","rust"],"backgroundTag":"unsupported-mime-type","analyzedSha":"221e52ae323febfd399bd7d067918fc43648cfb3","analyzedAt":"2026-08-20T16:12:39.808Z","contentChangedAt":"2026-08-20T16:12:39.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T20:17:18.057Z"}