use maidsafe_utilities::serialisation::SerialisationError;
pub const LAUNCHER_ERROR_START_RANGE: i32 = ::safe_dns::errors::DNS_ERROR_START_RANGE - 500;
pub enum LauncherError {
CoreError(Box<::safe_core::errors::CoreError>),
NfsError(Box<::safe_nfs::errors::NfsError>),
DnsError(Box<::safe_dns::errors::DnsError>),
IpcListenerCouldNotBeBound,
IpcListenerAborted(::std::io::Error),
IpcStreamCloneError(::std::io::Error),
ReceiverChannelDisconnected,
IpcSessionTerminated(Option<::std::io::Error>),
FailedReadingStreamPayloadSize,
FailedWritingStreamPayloadSize,
PathNotFound,
InvalidPath,
PermissionDenied,
JsonParseError(::rustc_serialize::json::ParserError),
JsonDecodeError(::rustc_serialize::json::DecoderError),
SpecificParseError(String),
JsonEncodeError(::rustc_serialize::json::EncoderError),
SymmetricDecipherFailure,
AppAlreadyAdded,
AppNotRegistered,
AppActivationFailed(::std::io::Error),
ReadPayloadSizeProhibitive,
LocalConfigAccessFailed(String),
Unexpected(String),
UnsuccessfulEncodeDecode(SerialisationError),
}
impl From<SerialisationError> for LauncherError {
fn from(error: SerialisationError) -> LauncherError {
LauncherError::UnsuccessfulEncodeDecode(error)
}
}
impl<'a> From<&'a str> for LauncherError {
fn from(error: &'a str) -> LauncherError {
LauncherError::Unexpected(error.to_string())
}
}
impl From<::safe_core::errors::CoreError> for LauncherError {
fn from(error: ::safe_core::errors::CoreError) -> LauncherError {
LauncherError::CoreError(Box::new(error))
}
}
impl From<::safe_nfs::errors::NfsError> for LauncherError {
fn from(error: ::safe_nfs::errors::NfsError) -> LauncherError {
LauncherError::NfsError(Box::new(error))
}
}
impl From<::safe_dns::errors::DnsError> for LauncherError {
fn from(error: ::safe_dns::errors::DnsError) -> LauncherError {
LauncherError::DnsError(Box::new(error))
}
}
impl From<::rustc_serialize::json::ParserError> for LauncherError {
fn from(error: ::rustc_serialize::json::ParserError) -> LauncherError {
LauncherError::JsonParseError(error)
}
}
impl From<::rustc_serialize::json::EncoderError> for LauncherError {
fn from(error: ::rustc_serialize::json::EncoderError) -> LauncherError {
LauncherError::JsonEncodeError(error)
}
}
impl From<::rustc_serialize::json::DecoderError> for LauncherError {
fn from(error: ::rustc_serialize::json::DecoderError) -> LauncherError {
LauncherError::JsonDecodeError(error)
}
}
impl Into<i32> for LauncherError {
fn into(self) -> i32 {
match self {
LauncherError::CoreError(error) => (*error).into(),
LauncherError::NfsError(error) => (*error).into(),
LauncherError::DnsError(error) => (*error).into(),
LauncherError::IpcListenerCouldNotBeBound => LAUNCHER_ERROR_START_RANGE - 1,
LauncherError::IpcListenerAborted(_) => LAUNCHER_ERROR_START_RANGE - 2,
LauncherError::IpcStreamCloneError(_) => LAUNCHER_ERROR_START_RANGE - 3,
LauncherError::ReceiverChannelDisconnected => LAUNCHER_ERROR_START_RANGE - 4,
LauncherError::IpcSessionTerminated(_) => LAUNCHER_ERROR_START_RANGE - 5,
LauncherError::FailedReadingStreamPayloadSize => LAUNCHER_ERROR_START_RANGE - 6,
LauncherError::FailedWritingStreamPayloadSize => LAUNCHER_ERROR_START_RANGE - 7,
LauncherError::PathNotFound => LAUNCHER_ERROR_START_RANGE - 8,
LauncherError::InvalidPath => LAUNCHER_ERROR_START_RANGE - 9,
LauncherError::PermissionDenied => LAUNCHER_ERROR_START_RANGE - 10,
LauncherError::JsonParseError(_) => LAUNCHER_ERROR_START_RANGE - 11,
LauncherError::JsonDecodeError(_) => LAUNCHER_ERROR_START_RANGE - 12,
LauncherError::SpecificParseError(_) => LAUNCHER_ERROR_START_RANGE - 13,
LauncherError::JsonEncodeError(_) => LAUNCHER_ERROR_START_RANGE - 14,
LauncherError::SymmetricDecipherFailure => LAUNCHER_ERROR_START_RANGE - 15,
LauncherError::AppAlreadyAdded => LAUNCHER_ERROR_START_RANGE - 16,
LauncherError::AppNotRegistered => LAUNCHER_ERROR_START_RANGE - 17,
LauncherError::AppActivationFailed(_) => LAUNCHER_ERROR_START_RANGE - 18,
LauncherError::ReadPayloadSizeProhibitive => LAUNCHER_ERROR_START_RANGE - 19,
LauncherError::LocalConfigAccessFailed(_) => LAUNCHER_ERROR_START_RANGE - 20,
LauncherError::Unexpected(_) => LAUNCHER_ERROR_START_RANGE - 21,
LauncherError::UnsuccessfulEncodeDecode(_) => LAUNCHER_ERROR_START_RANGE - 22,
}
}
}
impl ::std::fmt::Debug for LauncherError {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
match *self {
LauncherError::CoreError(ref error) => write!(f, "LauncherError::CoreError -> {:?}", error),
LauncherError::NfsError(ref error) => write!(f, "LauncherError::NfsError -> {:?}", error),
LauncherError::DnsError(ref error) => write!(f, "LauncherError::DnsError -> {:?}", error),
LauncherError::IpcListenerCouldNotBeBound => write!(f, "LauncherError::IpcListenerCouldNotBeBound"),
LauncherError::IpcListenerAborted(ref error) => write!(f, "LauncherError::IpcListenerAborted -> {:?}", error),
LauncherError::IpcStreamCloneError(ref error) => write!(f, "LauncherError::IpcStreamCloneError -> {:?}", error),
LauncherError::ReceiverChannelDisconnected => write!(f, "LauncherError::ReceiverChannelDisconnected"),
LauncherError::IpcSessionTerminated(ref error) => write!(f, "LauncherError::IpcSessionTerminated -> {:?}", error),
LauncherError::FailedReadingStreamPayloadSize => write!(f, "LauncherError::FailedReadingStreamPayloadSize"),
LauncherError::FailedWritingStreamPayloadSize => write!(f, "LauncherError::FailedWritingStreamPayloadSize"),
LauncherError::PathNotFound => write!(f, "LauncherError::PathNotFound"),
LauncherError::InvalidPath => write!(f, "LauncherError::InvalidPath"),
LauncherError::PermissionDenied => write!(f, "LauncherError::PermissionDenied"),
LauncherError::JsonParseError(ref error) => write!(f, "LauncherError::JsonParseError -> {:?}", error),
LauncherError::JsonDecodeError(ref error) => write!(f, "LauncherError::JsonDecodeError -> {:?}", error),
LauncherError::SpecificParseError(ref error) => write!(f, "LauncherError::SpecificParseError -> {:?}", error),
LauncherError::JsonEncodeError(ref error) => write!(f, "LauncherError::JsonEncodeError -> {:?}", error),
LauncherError::SymmetricDecipherFailure => write!(f, "LauncherError::SymmetricDecipherFailure"),
LauncherError::AppAlreadyAdded => write!(f, "LauncherError::AppAlreadyAdded"),
LauncherError::AppNotRegistered => write!(f, "LauncherError::AppNotRegistered"),
LauncherError::AppActivationFailed(ref error) => write!(f, "LauncherError::AppActivationFailed -> {:?}", error),
LauncherError::ReadPayloadSizeProhibitive => write!(f, "LauncherError::ReadPayloadSizeProhibitive"),
LauncherError::LocalConfigAccessFailed(ref error) => write!(f, "LauncherError::LocalConfigAccessFailed -> {:?}", error),
LauncherError::Unexpected(ref error) => write!(f, "LauncherError::Unexpected{{{:?}}}", error),
LauncherError::UnsuccessfulEncodeDecode(ref err) => write!(f, "LauncherError::UnsuccessfulEncodeDecode -> {:?}", err),
}
}
}