From de1fb673b27e03217729522efb9e2bee93591f16 Mon Sep 17 00:00:00 2001 From: Alexey Galakhov Date: Fri, 3 Feb 2017 22:32:05 +0100 Subject: [PATCH] error: correct UTF-8 error handling --- src/error.rs | 14 +++++++------- src/protocol/message.rs | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/error.rs b/src/error.rs index 9126f09..b2c446d 100644 --- a/src/error.rs +++ b/src/error.rs @@ -25,7 +25,7 @@ pub enum Error { /// Protocol violation Protocol(Cow<'static, str>), /// UTF coding error - Utf8(str::Utf8Error), + Utf8, /// Invlid URL. Url(Cow<'static, str>), /// HTTP error. @@ -39,7 +39,7 @@ impl fmt::Display for Error { Error::Io(ref err) => write!(f, "IO error: {}", err), Error::Capacity(ref msg) => write!(f, "Space limit exceeded: {}", msg), Error::Protocol(ref msg) => write!(f, "WebSocket protocol error: {}", msg), - Error::Utf8(ref err) => write!(f, "UTF-8 encoding error: {}", err), + Error::Utf8 => write!(f, "UTF-8 encoding error"), Error::Url(ref msg) => write!(f, "URL error: {}", msg), Error::Http(code) => write!(f, "HTTP code: {}", code), } @@ -53,7 +53,7 @@ impl ErrorTrait for Error { Error::Io(ref err) => err.description(), Error::Capacity(ref msg) => msg.borrow(), Error::Protocol(ref msg) => msg.borrow(), - Error::Utf8(ref err) => err.description(), + Error::Utf8 => "", Error::Url(ref msg) => msg.borrow(), Error::Http(_) => "", } @@ -67,14 +67,14 @@ impl From for Error { } impl From for Error { - fn from(err: str::Utf8Error) -> Self { - Error::Utf8(err) + fn from(_: str::Utf8Error) -> Self { + Error::Utf8 } } impl From for Error { - fn from(err: string::FromUtf8Error) -> Self { - Error::Utf8(err.utf8_error()) + fn from(_: string::FromUtf8Error) -> Self { + Error::Utf8 } } diff --git a/src/protocol/message.rs b/src/protocol/message.rs index 1b954d7..5e76be9 100644 --- a/src/protocol/message.rs +++ b/src/protocol/message.rs @@ -31,12 +31,12 @@ mod string_collect { utf8::Result::Ok | utf8::Result::Incomplete => Ok(()), utf8::Result::Error { remaining_input_after_error: _ } => - Err(Error::Protocol("Invalid UTF8".into())), // FIXME + Err(Error::Utf8), } } pub fn into_string(self) -> Result { if self.decoder.has_incomplete_sequence() { - Err(Error::Protocol("Invalid UTF8".into())) // FIXME + Err(Error::Utf8) } else { Ok(self.data) }