diff --git a/src/client/transport.rs b/src/client/transport.rs index 39dc2e5..1c42986 100644 --- a/src/client/transport.rs +++ b/src/client/transport.rs @@ -193,7 +193,7 @@ where } fn close(&mut self) -> Poll<(), Self::SinkError> { - self.inner.close() + self.inner.close().map_err(|e| e.into()) } } diff --git a/src/error.rs b/src/error.rs index 8177251..7ced8f5 100644 --- a/src/error.rs +++ b/src/error.rs @@ -18,6 +18,7 @@ use toml::de::Error as TomlReadError; use toml::ser::Error as TomlWriteError; use proto::Message; +use proto::error::{ProtocolError, MessageParseError}; /// A specialized `Result` type for the `irc` crate. pub type Result = ::std::result::Result; @@ -107,52 +108,6 @@ pub enum IrcError { }, } -/// Errors that occur when parsing messages. -#[derive(Debug, Fail)] -pub enum MessageParseError { - /// The message was empty. - #[fail(display = "empty message")] - EmptyMessage, - - /// The command was invalid (i.e. missing). - #[fail(display = "invalid command")] - InvalidCommand, - - /// The mode string was malformed. - #[fail(display = "invalid mode string: {}", string)] - InvalidModeString { - /// The invalid mode string. - string: String, - /// The detailed mode parsing error. - #[cause] - cause: ModeParseError, - }, - - /// The subcommand used was invalid. - #[fail(display = "invalid {} subcommand: {}", cmd, sub)] - InvalidSubcommand { - /// The command whose invalid subcommand was referenced. - cmd: &'static str, - /// The invalid subcommand. - sub: String, - } -} - -/// Errors that occur while parsing mode strings. -#[derive(Debug, Fail)] -pub enum ModeParseError { - /// Invalid modifier used in a mode string (only + and - are valid). - #[fail(display = "invalid mode modifier: {}", modifier)] - InvalidModeModifier { - /// The invalid mode modifier. - modifier: char, - }, - - /// Missing modifier used in a mode string. - #[fail(display = "missing mode modifier")] - MissingModeModifier, -} - /// Errors that occur with configurations. #[derive(Debug, Fail)] pub enum ConfigError { @@ -210,6 +165,17 @@ pub enum TomlError { Write(#[cause] TomlWriteError), } +impl From for IrcError { + fn from(e: ProtocolError) -> IrcError { + match e { + ProtocolError::Io(e) => IrcError::Io(e), + ProtocolError::InvalidMessage { string, cause } => IrcError::InvalidMessage { + string, cause + }, + } + } +} + impl From for IrcError { fn from(e: IoError) -> IrcError { IrcError::Io(e) diff --git a/src/lib.rs b/src/lib.rs index ebc108b..ec1c275 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -48,6 +48,7 @@ extern crate failure; extern crate encoding; #[macro_use] extern crate futures; +pub extern crate irc_proto as proto; #[macro_use] extern crate log; extern crate native_tls;