#[cfg(feature = "artifactory")]
use curl::ErrCode;
use docopt;
use git2;
#[cfg(feature = "ssh2")]
use ssh2::Error as Ssh2Error;
use std::error::Error;
use std::fmt;
use std::io;
use std::num::ParseIntError;
use std::string::FromUtf8Error;
use self::GitBoxError::*;
#[derive(Debug)]
pub enum GitBoxError {
#[cfg(feature = "artifactory")]
CURL(ErrCode),
Docopt(docopt::Error),
Git(git2::Error),
IO(io::Error),
PARSEINT(ParseIntError),
PARSESTR(FromUtf8Error),
#[cfg(feature = "ssh2")]
SSH(Ssh2Error),
Other(&'static str),
}
impl fmt::Display for GitBoxError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
writeln!(f, "test")
}
}
impl Error for GitBoxError {
fn description(&self) -> &str {
match *self {
#[cfg(feature = "artifactory")]
CURL(_) => "CurlError",
_ => "Other",
}
}
fn cause(&self) -> Option<&Error> {
match *self {
#[cfg(feature = "artifactory")]
CURL(ref e) => Some(e),
_ => None,
}
}
}
#[cfg(feature = "artifactory")]
impl From<ErrCode> for GitBoxError {
fn from(err: ErrCode) -> GitBoxError {
CURL(err)
}
}
impl From<docopt::Error> for GitBoxError {
fn from(err: docopt::Error) -> GitBoxError {
Docopt(err)
}
}
impl From<git2::Error> for GitBoxError {
fn from(err: git2::Error) -> GitBoxError {
Git(err)
}
}
impl From<io::Error> for GitBoxError {
fn from(err: io::Error) -> GitBoxError {
IO(err)
}
}
#[cfg(feature = "ssh2")]
impl From<Ssh2Error> for GitBoxError {
fn from(err: Ssh2Error) -> GitBoxError {
SSH(err)
}
}
impl From<ParseIntError> for GitBoxError {
fn from(err: ParseIntError) -> GitBoxError {
PARSEINT(err)
}
}
impl From<FromUtf8Error> for GitBoxError {
fn from(err: FromUtf8Error) -> GitBoxError {
PARSESTR(err)
}
}