[librsvg: 26/32] Replace LoadingError::Glib(gerror) with LoadingError::Io(String)
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 26/32] Replace LoadingError::Glib(gerror) with LoadingError::Io(String)
- Date: Fri, 4 Dec 2020 21:11:32 +0000 (UTC)
commit d76aba8f5d4f54f4278be8d34fb250fba254d6ec
Author: Federico Mena Quintero <federico gnome org>
Date: Thu Dec 3 14:32:01 2020 -0600
Replace LoadingError::Glib(gerror) with LoadingError::Io(String)
This is not ideal; not all Glib errors are I/O errors, but we don't do
anything to distinguish them elsewhere.
It may make sense to move to a Box<dyn Error> at some point.
src/error.rs | 12 +++++++-----
src/xml/mod.rs | 2 +-
src/xml/xml2_load.rs | 2 +-
3 files changed, 9 insertions(+), 7 deletions(-)
---
diff --git a/src/error.rs b/src/error.rs
index 249ed694..65902b82 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -337,8 +337,8 @@ pub enum LoadingError {
/// There is no `<svg>` root element in the XML.
NoSvgRoot,
- /// Generally an I/O error, or another error from GIO.
- Glib(glib::Error),
+ /// I/O error.
+ Io(String),
/// A particular implementation-defined limit was exceeded.
LimitExceeded(String),
@@ -357,7 +357,7 @@ impl fmt::Display for LoadingError {
LoadingError::BadUrl => write!(f, "invalid URL"),
LoadingError::BadCss => write!(f, "invalid CSS"),
LoadingError::NoSvgRoot => write!(f, "XML does not have <svg> root"),
- LoadingError::Glib(ref e) => e.fmt(f),
+ LoadingError::Io(ref s) => write!(f, "I/O error: {}", s),
LoadingError::LimitExceeded(ref s) => write!(f, "limit exceeded: {}", s),
LoadingError::Other(ref s) => write!(f, "{}", s),
}
@@ -366,7 +366,9 @@ impl fmt::Display for LoadingError {
impl From<glib::Error> for LoadingError {
fn from(e: glib::Error) -> LoadingError {
- LoadingError::Glib(e)
+ // FIXME: this is somewhat fishy; not all GError are I/O errors, but in librsvg
+ // most GError do come from gio. Some come from GdkPixbufLoader, though.
+ LoadingError::Io(format!("{}", e))
}
}
@@ -374,7 +376,7 @@ impl From<IoError> for LoadingError {
fn from(e: IoError) -> LoadingError {
match e {
IoError::BadDataUrl => LoadingError::BadUrl,
- IoError::Glib(e) => LoadingError::Glib(e),
+ IoError::Glib(e) => LoadingError::Io(format!("{}", e)),
}
}
}
diff --git a/src/xml/mod.rs b/src/xml/mod.rs
index 89f4e899..a7c125de 100644
--- a/src/xml/mod.rs
+++ b/src/xml/mod.rs
@@ -561,7 +561,7 @@ impl XmlState {
// FIXME: pass a cancellable
self.parse_from_stream(&stream, None).map_err(|e| match e {
- LoadingError::Glib(_) => AcquireError::ResourceError,
+ LoadingError::Io(_) => AcquireError::ResourceError,
LoadingError::XmlParseError(s) => AcquireError::FatalError(s),
_ => AcquireError::FatalError(String::from("unknown error")),
})
diff --git a/src/xml/xml2_load.rs b/src/xml/xml2_load.rs
index 3954fcf9..10ecf712 100644
--- a/src/xml/xml2_load.rs
+++ b/src/xml/xml2_load.rs
@@ -457,7 +457,7 @@ impl Xml2Parser {
let io_error = err_ref.take();
if let Some(io_error) = io_error {
- Err(LoadingError::Glib(io_error))
+ Err(LoadingError::from(io_error))
} else if !xml_parse_success {
let xerr = xmlCtxtGetLastError(parser as *mut _);
let msg = xml2_error_to_string(xerr);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]