Skip to content

Commit

Permalink
refactor(proto): return Error::Incomplete instead of UnexpectedEof
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmonstar committed Jan 11, 2018
1 parent 30f7f1d commit 7888451
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
18 changes: 18 additions & 0 deletions src/proto/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,21 @@ where I: AsyncRead + AsyncWrite,
fn poll_incoming(&mut self) -> Poll<Option<Frame<super::MessageHead<T::Incoming>, 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");
Expand All @@ -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,
}))),
Expand Down
18 changes: 1 addition & 17 deletions src/proto/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ impl<T: AsyncRead + AsyncWrite> Buffered<T> {
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);
}
_ => {},
}
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ test! {
body: None,
proxy: false,
error: |err| match err {
&hyper::Error::Io(_) => true,
&hyper::Error::Incomplete => true,
_ => false,
},
}
Expand Down

0 comments on commit 7888451

Please sign in to comment.