Nicely report API failure errors in CLI client (WIP)

This commit is contained in:
timvisee 2018-03-27 01:50:02 +02:00
parent 5ae016192c
commit 4ddfbeb4b6
No known key found for this signature in database
GPG key ID: 109CBA0BF74036C2
6 changed files with 46 additions and 22 deletions

View file

@ -1,21 +1,40 @@
#[cfg(feature = "clipboard")]
extern crate clipboard;
extern crate failure;
extern crate open;
#[cfg(feature = "clipboard")]
use std::error::Error;
use std::error::Error as StdError;
use std::fmt::{Debug, Display};
use std::io::Error as IoError;
use std::process::{exit, ExitStatus};
#[cfg(feature = "clipboard")]
use self::clipboard::{ClipboardContext, ClipboardProvider};
use self::failure::{Fail};
use ffsend_api::url::Url;
/// Quit the application with an error code,
/// and print the given error message.
pub fn quit_error<S: AsRef<str>>(err: S) -> ! {
/// and print the given error.
pub fn quit_error<E: Fail>(err: E) -> ! {
// Print the error message
eprintln!("error: {}", err.as_ref());
eprintln!("error: {}", err);
// Quit
exit(1);
}
/// Quit the application with an error code,
/// and print the given error message.
pub fn quit_error_msg<S>(err: S) -> !
where
S: AsRef<str> + Display + Debug + Sync + Send + 'static
{
// TODO: forward the error the `quit_error` here
// quit_error(failure::err_msg(err));
// Print the error message
eprintln!("error: {}", err);
// Quit
exit(1);
@ -35,7 +54,7 @@ pub fn open_path(path: &str) -> Result<ExitStatus, IoError> {
/// Set the clipboard of the user to the given `content` string.
#[cfg(feature = "clipboard")]
pub fn set_clipboard(content: String) -> Result<(), Box<Error>> {
pub fn set_clipboard(content: String) -> Result<(), Box<StdError>> {
let mut context: ClipboardContext = ClipboardProvider::new()?;
context.set_contents(content)
}