Skip to content

Commit

Permalink
images: improve logging when things are weird
Browse files Browse the repository at this point in the history
refs: #3366
  • Loading branch information
wez committed Mar 26, 2023
1 parent d491c73 commit 727cd95
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 5 additions & 1 deletion term/src/terminalstate/image.rs
Expand Up @@ -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")?;

Expand Down Expand Up @@ -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,
Expand Down
10 changes: 9 additions & 1 deletion term/src/terminalstate/iterm.rs
Expand Up @@ -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;
}

Expand Down

0 comments on commit 727cd95

Please sign in to comment.