[librsvg: 25/32] Replace RenderingError::Cairo(status) with RenderingError::Rendering(String)




commit 5e4e295f1ac8e8e107756eb3e48a13f921356eea
Author: Federico Mena Quintero <federico gnome org>
Date:   Thu Dec 3 13:48:10 2020 -0600

    Replace RenderingError::Cairo(status) with RenderingError::Rendering(String)
    
    This is a somewhat handwavy way of accomodating different rendering
    backends.  Maybe we'll move to a Rendering(Box<&dyn Error>) at some point?

 src/error.rs           | 10 +++++-----
 src/filters/context.rs |  2 +-
 src/filters/error.rs   | 13 +++++--------
 src/handle.rs          |  2 +-
 4 files changed, 12 insertions(+), 15 deletions(-)
---
diff --git a/src/error.rs b/src/error.rs
index 53711f45..249ed694 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -123,8 +123,8 @@ impl fmt::Display for DefsLookupErrorKind {
 #[non_exhaustive]
 #[derive(Debug, Clone, PartialEq)]
 pub enum RenderingError {
-    /// A Cairo error happened during rendering.
-    Cairo(cairo::Status),
+    /// An error from the rendering backend.
+    Rendering(String),
 
     /// A particular implementation-defined limit was exceeded.
     LimitExceeded(String),
@@ -153,11 +153,11 @@ impl error::Error for RenderingError {}
 impl fmt::Display for RenderingError {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         match *self {
+            RenderingError::Rendering(ref s) => write!(f, "rendering error: {}", s),
             RenderingError::LimitExceeded(ref s) => write!(f, "limit exceeded: {}", s),
-            RenderingError::OutOfMemory(ref s) => write!(f, "out of memory: {}", s),
-            RenderingError::Cairo(ref status) => write!(f, "cairo error: {:?}", status),
             RenderingError::IdNotFound => write!(f, "element id not found"),
             RenderingError::InvalidId(ref s) => write!(f, "invalid id: {:?}", s),
+            RenderingError::OutOfMemory(ref s) => write!(f, "out of memory: {}", s),
         }
     }
 }
@@ -166,7 +166,7 @@ impl From<cairo::Status> for RenderingError {
     fn from(e: cairo::Status) -> RenderingError {
         assert!(e != cairo::Status::Success);
 
-        RenderingError::Cairo(e)
+        RenderingError::Rendering(format!("{:?}", e))
     }
 }
 
diff --git a/src/filters/context.rs b/src/filters/context.rs
index 69544490..e8717276 100644
--- a/src/filters/context.rs
+++ b/src/filters/context.rs
@@ -215,7 +215,7 @@ impl FilterContext {
             .unwrap()
             .as_ref()
             .map(|surf| surf.clone())
-            .map_err(|&s| s)
+            .map_err(|e| e.clone())
     }
 
     /// Converts this `FilterContext` into the surface corresponding to the output of the filter
diff --git a/src/filters/error.rs b/src/filters/error.rs
index 9e33424b..b8ebe21f 100644
--- a/src/filters/error.rs
+++ b/src/filters/error.rs
@@ -3,7 +3,7 @@ use std::fmt;
 use crate::error::RenderingError;
 
 /// An enumeration of errors that can occur during filter primitive rendering.
-#[derive(Debug, Clone, Copy, Eq, PartialEq)]
+#[derive(Debug, Clone, PartialEq)]
 pub enum FilterError {
     /// The units on the filter bounds are invalid
     InvalidUnits,
@@ -16,6 +16,8 @@ pub enum FilterError {
     /// This means that either a failed intermediate surface creation or bad intermediate surface
     /// status.
     CairoError(cairo::Status),
+    /// Error from the rendering backend.
+    Rendering(RenderingError),
     /// A lighting filter has none or multiple light sources.
     InvalidLightSourceCount,
     /// A lighting filter input surface is too small.
@@ -36,6 +38,7 @@ impl fmt::Display for FilterError {
                 write!(f, "invalid status of the input surface: {}", status)
             }
             FilterError::CairoError(ref status) => write!(f, "Cairo error: {}", status),
+            FilterError::Rendering(ref e) => write!(f, "Rendering error: {}", e),
             FilterError::InvalidLightSourceCount => write!(f, "invalid light source count"),
             FilterError::LightingInputTooSmall => write!(
                 f,
@@ -56,12 +59,6 @@ impl From<cairo::Status> for FilterError {
 impl From<RenderingError> for FilterError {
     #[inline]
     fn from(e: RenderingError) -> Self {
-        if let RenderingError::Cairo(status) = e {
-            FilterError::CairoError(status)
-        } else {
-            // FIXME: this is just a dummy value; we should probably have a way to indicate
-            // an error in the underlying drawing process.
-            FilterError::CairoError(cairo::Status::InvalidStatus)
-        }
+        FilterError::Rendering(e)
     }
 }
diff --git a/src/handle.rs b/src/handle.rs
index 440a4117..1bfc90c4 100644
--- a/src/handle.rs
+++ b/src/handle.rs
@@ -379,7 +379,7 @@ fn check_cairo_context(cr: &cairo::Context) -> Result<(), RenderingError> {
     if status == cairo::Status::Success {
         Ok(())
     } else {
-        Err(RenderingError::Cairo(status))
+        Err(RenderingError::from(status))
     }
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]