[librsvg: 10/18] Don't convert to NodeError in parse_one_presentation_attribute()



commit d5826ff8c2cc6830160da7a0b4c14ba2595f63c6
Author: Federico Mena Quintero <federico gnome org>
Date:   Fri Dec 6 16:55:39 2019 -0600

    Don't convert to NodeError in parse_one_presentation_attribute()
    
    We don't propagate the error upstream, and this lets us have a simpler
    match on ValueErrorKind.

 rsvg_internals/src/error.rs      | 36 +++++++++++++++++++++---------------
 rsvg_internals/src/properties.rs |  4 ++--
 2 files changed, 23 insertions(+), 17 deletions(-)
---
diff --git a/rsvg_internals/src/error.rs b/rsvg_internals/src/error.rs
index cc12d511..829eb3da 100644
--- a/rsvg_internals/src/error.rs
+++ b/rsvg_internals/src/error.rs
@@ -23,6 +23,26 @@ pub enum ValueErrorKind {
     Value(String),
 }
 
+impl fmt::Display for ValueErrorKind {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        match *self {
+            ValueErrorKind::UnknownProperty => write!(f, "unknown property name"),
+
+            ValueErrorKind::Parse(ref n) => write!(
+                f,
+                "parse error: {}",
+                n.display
+            ),
+
+            ValueErrorKind::Value(ref s) => write!(
+                f,
+                "invalid value: {}",
+                s
+            ),
+        }
+    }
+}
+
 /// A complete error for an attribute and its erroneous value
 #[derive(Debug, Clone, PartialEq)]
 pub struct NodeError {
@@ -62,21 +82,7 @@ impl error::Error for NodeError {
 
 impl fmt::Display for NodeError {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-        match self.err {
-            ValueErrorKind::UnknownProperty => write!(f, "unknown property name"),
-
-            ValueErrorKind::Parse(ref n) => write!(
-                f,
-                "parse error: {}",
-                n.display
-            ),
-
-            ValueErrorKind::Value(ref s) => write!(
-                f,
-                "invalid value: {}",
-                s
-            ),
-        }
+        write!(f, "{:?}: {}", self.attr.expanded(), self.err)
     }
 }
 
diff --git a/rsvg_internals/src/properties.rs b/rsvg_internals/src/properties.rs
index 5b45f71b..33723b42 100644
--- a/rsvg_internals/src/properties.rs
+++ b/rsvg_internals/src/properties.rs
@@ -529,11 +529,11 @@ impl SpecifiedValues {
         // Presentation attributes don't accept shorthands, e.g. there is no
         // attribute like marker="#foo" and it needs to be set in the style attribute
         // like style="marker: #foo;".  So, pass false for accept_shorthands here.
-        match parse_property(&attr, &mut parser, false).attribute(attr.clone()) {
+        match parse_property(&attr, &mut parser, false) {
             Ok(prop) => self.set_parsed_property(&prop),
 
             // not a presentation attribute
-            Err(NodeError { err: ValueErrorKind::UnknownProperty, .. }) => (),
+            Err(ValueErrorKind::UnknownProperty) => (),
 
             Err(e) => {
                 // https://www.w3.org/TR/CSS2/syndata.html#unsupported-values


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