[librsvg: 18/32] Add a string description to RenderingError::OutOfMemory




commit a18d9d58c5fc50bf708e455145b64a0e1cf1574b
Author: Federico Mena Quintero <federico gnome org>
Date:   Thu Nov 26 15:52:36 2020 -0600

    Add a string description to RenderingError::OutOfMemory
    
    Only pixbuf_utils emits this right now, but in the future we can
    hopefully catch OOM elsewhere.

 src/c_api/pixbuf_utils.rs | 4 +++-
 src/error.rs              | 5 ++---
 2 files changed, 5 insertions(+), 4 deletions(-)
---
diff --git a/src/c_api/pixbuf_utils.rs b/src/c_api/pixbuf_utils.rs
index f82ccfe8..4d9b30a1 100644
--- a/src/c_api/pixbuf_utils.rs
+++ b/src/c_api/pixbuf_utils.rs
@@ -23,7 +23,9 @@ use crate::{
 fn pixbuf_new(width: i32, height: i32) -> Result<Pixbuf, RenderingError> {
     assert!(width > 0 && height > 0);
 
-    Pixbuf::new(Colorspace::Rgb, true, 8, width, height).ok_or(RenderingError::OutOfMemory)
+    Pixbuf::new(Colorspace::Rgb, true, 8, width, height).ok_or(RenderingError::OutOfMemory(
+        String::from("creating a Pixbuf"),
+    ))
 }
 
 pub fn empty_pixbuf() -> Result<Pixbuf, RenderingError> {
diff --git a/src/error.rs b/src/error.rs
index c535998c..8c9acf9a 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -145,8 +145,7 @@ pub enum RenderingError {
     InvalidId(String),
 
     /// Not enough memory was available for rendering.
-    // FIXME: right now this is only returned from pixbuf_utils.rs
-    OutOfMemory,
+    OutOfMemory(String),
 }
 
 impl From<DefsLookupErrorKind> for RenderingError {
@@ -164,7 +163,7 @@ impl fmt::Display for RenderingError {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         match *self {
             RenderingError::LimitExceeded(ref s) => write!(f, "limit exceeded: {}", s),
-            RenderingError::OutOfMemory => write!(f, "out of memory"),
+            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),


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