diff --git a/codex-rs/protocol/src/models.rs b/codex-rs/protocol/src/models.rs index f44d847099..755b59f535 100644 --- a/codex-rs/protocol/src/models.rs +++ b/codex-rs/protocol/src/models.rs @@ -158,6 +158,19 @@ fn local_image_error_placeholder( } } +fn invalid_image_error_placeholder( + path: &std::path::Path, + error: impl std::fmt::Display, +) -> ContentItem { + ContentItem::InputText { + text: format!( + "Image located at `{}` is invalid: {}", + path.display(), + error + ), + } +} + impl From for ResponseItem { fn from(item: ResponseInputItem) -> Self { match item { @@ -247,9 +260,10 @@ impl From> for ResponseInputItem { image_url: image.into_data_url(), }, Err(err) => { - tracing::warn!("Failed to resize image {}: {}", path.display(), err); if matches!(&err, ImageProcessingError::Read { .. }) { local_image_error_placeholder(&path, &err) + } else if err.is_invalid_image() { + invalid_image_error_placeholder(&path, &err) } else { match std::fs::read(&path) { Ok(bytes) => { @@ -365,6 +379,7 @@ impl Serialize for FunctionCallOutputPayload { where S: Serializer, { + tracing::error!("Payload: {:?}", self); if let Some(items) = &self.content_items { items.serialize(serializer) } else { @@ -452,7 +467,7 @@ fn convert_content_blocks_to_items( ) -> Option> { let mut saw_image = false; let mut items = Vec::with_capacity(blocks.len()); - + tracing::warn!("Blocks: {:?}", blocks); for block in blocks { match block { ContentBlock::TextContent(text) => { diff --git a/codex-rs/utils/image/src/error.rs b/codex-rs/utils/image/src/error.rs index ffd0a7850e..6bd055115d 100644 --- a/codex-rs/utils/image/src/error.rs +++ b/codex-rs/utils/image/src/error.rs @@ -1,3 +1,4 @@ +use image::ImageError; use image::ImageFormat; use std::path::PathBuf; use thiserror::Error; @@ -23,3 +24,15 @@ pub enum ImageProcessingError { source: image::ImageError, }, } + +impl ImageProcessingError { + pub fn is_invalid_image(&self) -> bool { + matches!( + self, + ImageProcessingError::Decode { + source: ImageError::Decoding(_), + .. + } + ) + } +}