From 727cd95dcdacea9bf1d57bab7f0ccdc54eb9942a Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sat, 25 Mar 2023 18:55:26 -0700 Subject: [PATCH] images: improve logging when things are weird refs: https://github.com/wez/wezterm/issues/3366 --- term/src/terminalstate/image.rs | 6 +++++- term/src/terminalstate/iterm.rs | 10 +++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/term/src/terminalstate/image.rs b/term/src/terminalstate/image.rs index a5893642e..9155ff95f 100644 --- a/term/src/terminalstate/image.rs +++ b/term/src/terminalstate/image.rs @@ -110,7 +110,7 @@ impl TerminalState { let first_row = self.screen().visible_row_to_stable_row(self.cursor.y); let mut ypos = NotNan::new(params.source_origin_y as f32 / params.image_height as f32) - .context("computing ypos")?; + .with_context(|| format!("computing ypos {params:#?}"))?; let start_xpos = NotNan::new(params.source_origin_x as f32 / params.image_width as f32) .context("computing xpos")?; @@ -256,9 +256,13 @@ pub(crate) fn check_image_dimensions(width: u32, height: u32) -> anyhow::Result< SizeFormatter::new(MAX_IMAGE_SIZE, DECIMAL), ); } + if size == 0 { + anyhow::bail!("Ignoring image with 0x0 dimensions"); + } Ok(()) } +#[derive(Debug)] pub(crate) struct ImageInfo { pub width: u32, pub height: u32, diff --git a/term/src/terminalstate/iterm.rs b/term/src/terminalstate/iterm.rs index d5480ce6c..6a32974ef 100644 --- a/term/src/terminalstate/iterm.rs +++ b/term/src/terminalstate/iterm.rs @@ -35,7 +35,15 @@ impl TerminalState { }; if let Err(err) = check_image_dimensions(info.width, info.height) { - log::error!("{}", err); + log::error!("{err:#}, {info:#?}"); + return; + } + + if self.pixel_width == 0 || self.pixel_height == 0 { + error!( + "my pixel dimensions are wacky! {}x{}", + self.pixel_width, self.pixel_height + ); return; }