libimagnotification: Move from error-chain to failure

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
Matthias Beyer 2018-10-30 18:40:50 +01:00
parent 72add24d87
commit 5627bbe454
5 changed files with 17 additions and 49 deletions

View file

@ -20,8 +20,9 @@ is-it-maintained-open-issues = { repository = "matthiasbeyer/imag" }
maintenance = { status = "actively-developed" }
[dependencies]
notify-rust = "3.4.2"
error-chain = "0.12"
notify-rust = "3.4.2"
failure = "0.1"
failure_derive = "0.1"
libimagerror = { version = "0.9.0", path = "../../../lib/core/libimagerror" }

View file

@ -1,36 +0,0 @@
//
// imag - the personal information management suite for the commandline
// Copyright (C) 2015-2018 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")
}
}
}

View file

@ -34,11 +34,10 @@
)]
extern crate notify_rust;
#[macro_use] extern crate error_chain;
extern crate failure;
extern crate libimagerror;
pub mod error;
pub mod notificator;
pub mod result_notification;

View file

@ -17,7 +17,7 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
use error::Result;
use failure::Fallible as Result;
/// A Notificator provides a function that can be called to notify about a certain object.
///
@ -34,7 +34,7 @@ pub mod default {
use std::fmt::Debug;
use std::fmt::Display;
use error::Result;
use failure::Fallible as Result;
use notify_rust::Notification as RustNotification;
use notify_rust::NotificationUrgency;

View file

@ -31,12 +31,11 @@ pub mod err {
use notify_rust::Notification as RustNotification;
use notify_rust::NotificationUrgency;
use error::ResultExt;
use error::NotificationErrorKind as NEK;
use notificator::default::Urgency;
use notificator::default::Notification;
use notificator::Notificator;
use error::Result;
use failure::Fallible as Result;
use failure::err_msg;
#[derive(Debug, Default, Clone)]
pub struct ErrorNotification(Notification, usize);
@ -64,7 +63,9 @@ pub mod err {
n.summary("[Error]");
n.urgency(urgency);
n.body(e.description());
try!(n.finalize().show().map(|_| ()).chain_err(|| NEK::Unknown));
let _ = n.finalize()
.show()
.map_err(|_| err_msg("Notification error"))?;
if u > 0 {
e.cause().map(|cause| trace_notify(urgency, cause, u - 1));
@ -105,7 +106,8 @@ pub mod ok {
use notificator::default::Notification;
use notificator::Notificator;
use error::Result;
use failure::Fallible as Result;
use failure::err_msg;
#[derive(Debug, Default, Clone)]
pub struct OkNotification(Notification);
@ -127,8 +129,10 @@ pub mod ok {
n.summary("[Ok]");
n.urgency(self.0.urgency.clone().into());
n.body(&"< >".to_owned());
n.finalize().show().map(|_| ())?;
Ok(())
n.finalize()
.show()
.map(|_| ())
.map_err(|_| err_msg("Notification error"))
}
}