Transform to use error-chain
This commit is contained in:
parent
7bdaaf35fc
commit
f0ae628687
5 changed files with 49 additions and 10 deletions
|
@ -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" }
|
||||
|
||||
|
|
36
lib/etc/libimagnotification/src/error.rs
Normal file
36
lib/etc/libimagnotification/src/error.rs
Normal file
|
@ -0,0 +1,36 @@
|
|||
//
|
||||
// imag - the personal information management suite for the commandline
|
||||
// Copyright (C) 2015, 2016 Matthias Beyer <mail@beyermatthias.de> 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")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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(())
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue