[librsvg: 1/2] Remove deprecated `description` from error types



commit 04f79203b786aadda22c49fd4d32609e58466da6
Author: Gabriel Majeri <gabriel majeri6 gmail com>
Date:   Mon Mar 30 22:19:28 2020 +0300

    Remove deprecated `description` from error types

 rsvg_internals/src/allowed_url.rs   | 29 +++++-------
 rsvg_internals/src/error.rs         | 90 +++++++++++++------------------------
 rsvg_internals/src/filters/error.rs | 42 +++++++----------
 rsvg_internals/src/path_parser.rs   | 20 +++------
 4 files changed, 63 insertions(+), 118 deletions(-)
---
diff --git a/rsvg_internals/src/allowed_url.rs b/rsvg_internals/src/allowed_url.rs
index 8be10a59..71f56bae 100644
--- a/rsvg_internals/src/allowed_url.rs
+++ b/rsvg_internals/src/allowed_url.rs
@@ -1,6 +1,6 @@
 //! Determine which URLs are allowed for loading.
 
-use std::error::{self, Error};
+use std::error;
 use std::fmt;
 use std::io;
 use std::ops::Deref;
@@ -125,26 +125,21 @@ impl fmt::Display for AllowedUrl {
     }
 }
 
-impl error::Error for AllowedUrlError {
-    fn description(&self) -> &str {
-        match *self {
-            AllowedUrlError::HrefParseError(_) => "href parse error",
-            AllowedUrlError::BaseRequired => "base required",
-            AllowedUrlError::DifferentURISchemes => "different URI schemes",
-            AllowedUrlError::DisallowedScheme => "disallowed scheme",
-            AllowedUrlError::NotSiblingOrChildOfBaseFile => "not sibling or child of base file",
-            AllowedUrlError::InvalidPath => "invalid path",
-            AllowedUrlError::BaseIsRoot => "base is root",
-            AllowedUrlError::CanonicalizationError => "canonicalization error",
-        }
-    }
-}
+impl error::Error for AllowedUrlError {}
 
 impl fmt::Display for AllowedUrlError {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         match *self {
-            AllowedUrlError::HrefParseError(e) => write!(f, "{}: {}", self.description(), e),
-            _ => write!(f, "{}", self.description()),
+            AllowedUrlError::HrefParseError(e) => write!(f, "href parse error: {}", e),
+            AllowedUrlError::BaseRequired => write!(f, "base required"),
+            AllowedUrlError::DifferentURISchemes => write!(f, "different URI schemes"),
+            AllowedUrlError::DisallowedScheme => write!(f, "disallowed scheme"),
+            AllowedUrlError::NotSiblingOrChildOfBaseFile => {
+                write!(f, "not sibling or child of base file")
+            }
+            AllowedUrlError::InvalidPath => write!(f, "invalid path"),
+            AllowedUrlError::BaseIsRoot => write!(f, "base is root"),
+            AllowedUrlError::CanonicalizationError => write!(f, "canonicalization error"),
         }
     }
 }
diff --git a/rsvg_internals/src/error.rs b/rsvg_internals/src/error.rs
index 786fe281..aa2fefc2 100644
--- a/rsvg_internals/src/error.rs
+++ b/rsvg_internals/src/error.rs
@@ -1,6 +1,6 @@
 //! Error types.
 
-use std::error::{self, Error};
+use std::error;
 use std::fmt;
 
 use cssparser::{BasicParseError, BasicParseErrorKind, ParseErrorKind, ToCss};
@@ -112,6 +112,22 @@ pub enum RenderingError {
     HandleIsNotLoaded,
 }
 
+impl error::Error for RenderingError {}
+
+impl fmt::Display for RenderingError {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        match *self {
+            RenderingError::CircularReference => write!(f, "circular reference"),
+            RenderingError::InstancingLimit => write!(f, "instancing limit"),
+            RenderingError::InvalidHref => write!(f, "invalid href"),
+            RenderingError::OutOfMemory => write!(f, "out of memory"),
+            RenderingError::HandleIsNotLoaded => write!(f, "SVG data is not loaded into handle"),
+            RenderingError::Cairo(ref status) => write!(f, "cairo error: {:?}", status),
+            RenderingError::InvalidId(ref id) => write!(f, "invalid id: {:?}", id),
+        }
+    }
+}
+
 impl From<cairo::Status> for RenderingError {
     fn from(e: cairo::Status) -> RenderingError {
         assert!(e != cairo::Status::Success);
@@ -267,70 +283,24 @@ pub enum LoadingError {
     Unknown,
 }
 
-impl error::Error for LoadingError {
-    fn description(&self) -> &str {
-        match *self {
-            LoadingError::NoDataPassedToParser => "no data passed to parser",
-            LoadingError::CouldNotCreateXmlParser => "could not create XML parser",
-            LoadingError::XmlParseError(_) => "XML parse error",
-            LoadingError::BadUrl => "invalid URL",
-            LoadingError::BadDataUrl => "invalid data: URL",
-            LoadingError::BadStylesheet => "invalid stylesheet",
-            LoadingError::BadCss => "invalid CSS",
-            LoadingError::Cairo(_) => "cairo error",
-            LoadingError::EmptyData => "empty data",
-            LoadingError::SvgHasNoElements => "SVG has no elements",
-            LoadingError::RootElementIsNotSvg => "root element is not <svg>",
-            LoadingError::Glib(ref e) => e.description(),
-            LoadingError::Unknown => "unknown error",
-        }
-    }
-}
+impl error::Error for LoadingError {}
 
 impl fmt::Display for LoadingError {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         match *self {
-            LoadingError::Cairo(status) => write!(f, "cairo error: {:?}", status),
+            LoadingError::NoDataPassedToParser => write!(f, "no data passed to parser"),
             LoadingError::XmlParseError(ref s) => write!(f, "XML parse error: {}", s),
-            LoadingError::NoDataPassedToParser
-            | LoadingError::CouldNotCreateXmlParser
-            | LoadingError::BadUrl
-            | LoadingError::BadDataUrl
-            | LoadingError::BadStylesheet
-            | LoadingError::BadCss
-            | LoadingError::EmptyData
-            | LoadingError::SvgHasNoElements
-            | LoadingError::RootElementIsNotSvg
-            | LoadingError::Glib(_)
-            | LoadingError::Unknown => write!(f, "{}", self.description()),
-        }
-    }
-}
-
-impl error::Error for RenderingError {
-    fn description(&self) -> &str {
-        match *self {
-            RenderingError::Cairo(_) => "cairo error",
-            RenderingError::CircularReference => "circular reference",
-            RenderingError::InstancingLimit => "instancing limit",
-            RenderingError::InvalidId(_) => "invalid id",
-            RenderingError::InvalidHref => "invalid href",
-            RenderingError::OutOfMemory => "out of memory",
-            RenderingError::HandleIsNotLoaded => "SVG data is not loaded into handle",
-        }
-    }
-}
-
-impl fmt::Display for RenderingError {
-    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-        match *self {
-            RenderingError::Cairo(ref status) => write!(f, "cairo error: {:?}", status),
-            RenderingError::InvalidId(ref id) => write!(f, "invalid id: {:?}", id),
-            RenderingError::CircularReference
-            | RenderingError::InstancingLimit
-            | RenderingError::InvalidHref
-            | RenderingError::OutOfMemory
-            | RenderingError::HandleIsNotLoaded => write!(f, "{}", self.description()),
+            LoadingError::CouldNotCreateXmlParser => write!(f, "could not create XML parser"),
+            LoadingError::BadUrl => write!(f, "invalid URL"),
+            LoadingError::BadDataUrl => write!(f, "invalid data: URL"),
+            LoadingError::BadStylesheet => write!(f, "invalid stylesheet"),
+            LoadingError::BadCss => write!(f, "invalid CSS"),
+            LoadingError::Cairo(status) => write!(f, "cairo error: {:?}", status),
+            LoadingError::EmptyData => write!(f, "empty data"),
+            LoadingError::SvgHasNoElements => write!(f, "SVG has no elements"),
+            LoadingError::RootElementIsNotSvg => write!(f, "root element is not <svg>"),
+            LoadingError::Glib(ref e) => e.fmt(f),
+            LoadingError::Unknown => write!(f, "unknown error"),
         }
     }
 }
diff --git a/rsvg_internals/src/filters/error.rs b/rsvg_internals/src/filters/error.rs
index cf03a879..bce600df 100644
--- a/rsvg_internals/src/filters/error.rs
+++ b/rsvg_internals/src/filters/error.rs
@@ -25,38 +25,26 @@ pub enum FilterError {
     ChildNodeInError,
 }
 
-impl Error for FilterError {
-    #[inline]
-    fn description(&self) -> &str {
-        match *self {
-            FilterError::InvalidUnits => {
-                "unit identifiers are not allowed with primitiveUnits set to objectBoundingBox"
-            }
-            FilterError::InvalidInput => "invalid value of the `in` attribute",
-            FilterError::BadInputSurfaceStatus(_) => "invalid status of the input surface",
-            FilterError::CairoError(_) => "Cairo error",
-            FilterError::InvalidLightSourceCount => "invalid light source count",
-            FilterError::LightingInputTooSmall => {
-                "lighting filter input surface is too small (less than 2×2 pixels)"
-            }
-            FilterError::ChildNodeInError => "child node was in error",
-        }
-    }
-
-    #[inline]
-    fn cause(&self) -> Option<&dyn Error> {
-        None
-    }
-}
+impl Error for FilterError {}
 
 impl fmt::Display for FilterError {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         match *self {
-            FilterError::BadInputSurfaceStatus(ref status)
-            | FilterError::CairoError(ref status) => {
-                write!(f, "{}: {:?}", self.description(), status)
+            FilterError::InvalidUnits => write!(
+                f,
+                "unit identifiers are not allowed with primitiveUnits set to objectBoundingBox"
+            ),
+            FilterError::InvalidInput => write!(f, "invalid value of the `in` attribute"),
+            FilterError::BadInputSurfaceStatus(ref status) => {
+                write!(f, "invalid status of the input surface: {}", status)
             }
-            _ => write!(f, "{}", self.description()),
+            FilterError::CairoError(ref status) => write!(f, "Cairo error: {}", status),
+            FilterError::InvalidLightSourceCount => write!(f, "invalid light source count"),
+            FilterError::LightingInputTooSmall => write!(
+                f,
+                "lighting filter input surface is too small (less than 2×2 pixels)"
+            ),
+            FilterError::ChildNodeInError => write!(f, "child node was in error"),
         }
     }
 }
diff --git a/rsvg_internals/src/path_parser.rs b/rsvg_internals/src/path_parser.rs
index 2e05c3fa..0fe3b5e3 100644
--- a/rsvg_internals/src/path_parser.rs
+++ b/rsvg_internals/src/path_parser.rs
@@ -912,23 +912,15 @@ pub struct ParseError {
     pub kind: ErrorKind,
 }
 
-impl Error for ParseError {
-    fn description(&self) -> &str {
-        match self.kind {
-            ErrorKind::UnexpectedToken => "unexpected token",
-            ErrorKind::UnexpectedEof => "unexpected end of data",
-        }
-    }
-}
+impl Error for ParseError {}
 
 impl fmt::Display for ParseError {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-        write!(
-            f,
-            "error at position {}: {}",
-            self.position,
-            self.description()
-        )
+        let description = match self.kind {
+            ErrorKind::UnexpectedToken => "unexpected token",
+            ErrorKind::UnexpectedEof => "unexpected end of data",
+        };
+        write!(f, "error at position {}: {}", self.position, description)
     }
 }
 


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