diff --git a/lib/etc/libimagnotification/Cargo.toml b/lib/etc/libimagnotification/Cargo.toml index 510ffda0..88cd3852 100644 --- a/lib/etc/libimagnotification/Cargo.toml +++ b/lib/etc/libimagnotification/Cargo.toml @@ -15,6 +15,7 @@ homepage = "http://imag-pim.org" [dependencies] notify-rust = "3.4.2" +error-chain = "0.11" libimagerror = { version = "0.5.0", path = "../../../lib/core/libimagerror" } diff --git a/lib/etc/libimagnotification/src/error.rs b/lib/etc/libimagnotification/src/error.rs new file mode 100644 index 00000000..535a7c89 --- /dev/null +++ b/lib/etc/libimagnotification/src/error.rs @@ -0,0 +1,36 @@ +// +// imag - the personal information management suite for the commandline +// Copyright (C) 2015, 2016 Matthias Beyer and contributors +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; version +// 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +// + +error_chain! { + types { + NotificationError, NotificationErrorKind, ResultExt, Result; + } + + foreign_links { + NotifyError(::notify_rust::error::Error); + } + + errors { + Unknown { + description("Unknown Error") + display("Unknown Error") + } + } +} + diff --git a/lib/etc/libimagnotification/src/lib.rs b/lib/etc/libimagnotification/src/lib.rs index 7ecb963c..6e1f27f1 100644 --- a/lib/etc/libimagnotification/src/lib.rs +++ b/lib/etc/libimagnotification/src/lib.rs @@ -18,11 +18,11 @@ // extern crate notify_rust; +#[macro_use] extern crate error_chain; #[macro_use] extern crate libimagerror; pub mod error; pub mod notificator; -pub mod result; pub mod result_notification; diff --git a/lib/etc/libimagnotification/src/notificator.rs b/lib/etc/libimagnotification/src/notificator.rs index b10b8a1b..5772ff0d 100644 --- a/lib/etc/libimagnotification/src/notificator.rs +++ b/lib/etc/libimagnotification/src/notificator.rs @@ -17,7 +17,8 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -use result::Result; +use error::Result; +use error::ResultExt; /// A Notificator provides a function that can be called to notify about a certain object. /// @@ -34,7 +35,7 @@ pub mod default { use std::fmt::Debug; use std::fmt::Display; - use result::Result; + use error::Result; use notify_rust::Notification as RustNotification; use notify_rust::NotificationUrgency; diff --git a/lib/etc/libimagnotification/src/result_notification.rs b/lib/etc/libimagnotification/src/result_notification.rs index ca540de5..b458f767 100644 --- a/lib/etc/libimagnotification/src/result_notification.rs +++ b/lib/etc/libimagnotification/src/result_notification.rs @@ -31,12 +31,12 @@ pub mod err { use notify_rust::Notification as RustNotification; use notify_rust::NotificationUrgency; + use error::ResultExt; use error::NotificationErrorKind as NEK; - use error::MapErrInto; use notificator::default::Urgency; use notificator::default::Notification; use notificator::Notificator; - use result::Result; + use error::Result; #[derive(Debug, Default, Clone)] pub struct ErrorNotification(Notification, usize); @@ -64,7 +64,7 @@ pub mod err { n.summary("[Error]"); n.urgency(urgency.clone()); n.body(e.description()); - try!(n.finalize().show().map(|_| ()).map_err_into(NEK::NotificationError)); + try!(n.finalize().show().map(|_| ()).chain_err(|| NEK::Unknown)); if u > 0 { e.cause().map(|cause| trace_notify(urgency, cause, u - 1)); @@ -103,11 +103,11 @@ pub mod ok { use notify_rust::Notification as RustNotification; - use error::MapErrInto; - use error::NotificationErrorKind as NEK; use notificator::default::Notification; use notificator::Notificator; - use result::Result; + use error::NotificationErrorKind as NEK; + use error::Result; + use error::ResultExt; #[derive(Debug, Default, Clone)] pub struct OkNotification(Notification); @@ -129,7 +129,8 @@ pub mod ok { n.summary("[Ok]"); n.urgency(self.0.urgency.clone().into()); n.body(&"< >".to_owned()); - n.finalize().show().map(|_| ()).map_err_into(NEK::NotificationError) + n.finalize().show().map(|_| ())?; + Ok(()) } }