From 1429013dd15708d9e0f26661f261639661553cd2 Mon Sep 17 00:00:00 2001 From: Hajime-san <41257923+Hajime-san@users.noreply.github.com> Date: Thu, 24 Oct 2024 17:55:34 +0900 Subject: [PATCH] map lcms error --- ext/canvas/image_ops.rs | 10 ++++------ ext/canvas/lib.rs | 2 ++ runtime/errors.rs | 1 + 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/ext/canvas/image_ops.rs b/ext/canvas/image_ops.rs index bc28534550..baf5b00701 100644 --- a/ext/canvas/image_ops.rs +++ b/ext/canvas/image_ops.rs @@ -365,14 +365,12 @@ where &output_icc_profile, pixel_format, output_icc_profile.header_rendering_intent(), - ); + ) + .map_err(CanvasError::Lcms) + .unwrap(); for (x, y, mut pixel) in image.pixels() { - let pixel = match transformer { - Ok(ref transformer) => pixel.transform_color_profile(transformer), - // This arm will reach when the ffi call fails. - Err(_) => pixel, - }; + let pixel = pixel.transform_color_profile(&transformer); out.put_pixel(x, y, pixel); } diff --git a/ext/canvas/lib.rs b/ext/canvas/lib.rs index 5124c60043..3e1f0424f9 100644 --- a/ext/canvas/lib.rs +++ b/ext/canvas/lib.rs @@ -22,6 +22,8 @@ pub enum CanvasError { #[error("Cannot decode image '{0}'")] InvalidImage(String), #[error(transparent)] + Lcms(#[from] lcms2::Error), + #[error(transparent)] /// This error will be mapped to TypeError. Image(#[from] image::ImageError), } diff --git a/runtime/errors.rs b/runtime/errors.rs index 47cc40b1bd..73f7a822f3 100644 --- a/runtime/errors.rs +++ b/runtime/errors.rs @@ -603,6 +603,7 @@ fn get_canvas_error(e: &CanvasError) -> &'static str { match e { CanvasError::UnsupportedColorType(_) => "TypeError", CanvasError::InvalidImage(_) => "DOMExceptionInvalidStateError", + CanvasError::Lcms(_) => "TypeError", CanvasError::Image(_) => "TypeError", } }