From 7888451408f66b488dd7b285cbdb64bb87180480 Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Thu, 11 Jan 2018 11:45:28 -0800 Subject: [PATCH] refactor(proto): return Error::Incomplete instead of UnexpectedEof --- src/proto/conn.rs | 18 ++++++++++++++++++ src/proto/io.rs | 18 +----------------- tests/client.rs | 2 +- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/proto/conn.rs b/src/proto/conn.rs index 652c6714..92d4e1b5 100644 --- a/src/proto/conn.rs +++ b/src/proto/conn.rs @@ -58,6 +58,21 @@ where I: AsyncRead + AsyncWrite, fn poll_incoming(&mut self) -> Poll, super::Chunk, ::Error>>, io::Error> { trace!("Conn::poll_incoming()"); + #[derive(Debug)] + struct ParseEof; + + impl fmt::Display for ParseEof { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.write_str(::std::error::Error::description(self)) + } + } + + impl ::std::error::Error for ParseEof { + fn description(&self) -> &str { + "end of file reached before parsing could complete" + } + } + loop { if self.is_read_closed() { trace!("Conn::poll when closed"); @@ -73,6 +88,9 @@ where I: AsyncRead + AsyncWrite, Ok(Async::Ready(None)) => Ok(Async::Ready(None)), Ok(Async::NotReady) => Ok(Async::NotReady), Err(::Error::Io(err)) => Err(err), + Err(::Error::Incomplete) => { + Err(io::Error::new(io::ErrorKind::UnexpectedEof, ParseEof)) + }, Err(err) => Ok(Async::Ready(Some(Frame::Error { error: err, }))), diff --git a/src/proto/io.rs b/src/proto/io.rs index faa39fbf..098a5959 100644 --- a/src/proto/io.rs +++ b/src/proto/io.rs @@ -84,8 +84,7 @@ impl Buffered { match try_ready!(self.read_from_io()) { 0 => { trace!("parse eof"); - //TODO: utilize Error::Incomplete when Error type is redesigned - return Err(io::Error::new(io::ErrorKind::UnexpectedEof, ParseEof).into()); + return Err(::Error::Incomplete); } _ => {}, } @@ -333,21 +332,6 @@ impl WriteBuf { } } -#[derive(Debug)] -struct ParseEof; - -impl fmt::Display for ParseEof { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.write_str(::std::error::Error::description(self)) - } -} - -impl ::std::error::Error for ParseEof { - fn description(&self) -> &str { - "end of file reached before parsing could complete" - } -} - // TODO: Move tests to their own mod #[cfg(test)] use std::io::Read; diff --git a/tests/client.rs b/tests/client.rs index 958ceb7a..4e05742a 100644 --- a/tests/client.rs +++ b/tests/client.rs @@ -425,7 +425,7 @@ test! { body: None, proxy: false, error: |err| match err { - &hyper::Error::Io(_) => true, + &hyper::Error::Incomplete => true, _ => false, }, }