Carry irritant in parse error

This commit is contained in:
Tony Garnock-Jones 2019-10-17 15:41:42 +01:00
parent 06c2347e87
commit c41fe3df3e
2 changed files with 8 additions and 10 deletions

View File

@ -44,7 +44,7 @@ pub enum Out {
#[derive(Debug)]
pub enum DecodeError {
Read(value::decoder::Error),
Parse(value::error::Error),
Parse(value::error::Error, V),
}
impl From<io::Error> for DecodeError {
@ -53,12 +53,6 @@ impl From<io::Error> for DecodeError {
}
}
impl From<value::error::Error> for DecodeError {
fn from(v: value::error::Error) -> Self {
DecodeError::Parse(v)
}
}
//---------------------------------------------------------------------------
#[derive(Debug)]
@ -111,7 +105,10 @@ impl tokio::codec::Decoder for Codec {
let final_len = buf.len();
bs.advance(orig_len - final_len);
match res {
Ok(v) => Ok(Some(value::from_value(&v)?)),
Ok(v) => match value::from_value(&v) {
Ok(p) => Ok(Some(p)),
Err(e) => Err(DecodeError::Parse(e, v))
}
Err(value::decoder::Error::Eof) => Ok(None),
Err(e) => Err(DecodeError::Read(e)),
}

View File

@ -93,8 +93,9 @@ impl Peer {
to_send.push(err(s));
running = false;
}
Err(packets::DecodeError::Parse(e)) => {
to_send.push(err(&format!("Packet deserialization error: {:?}", e)));
Err(packets::DecodeError::Parse(e, v)) => {
to_send.push(err(&format!(
"Packet deserialization error ({}) decoding {:?} ", e, v)));
running = false;
}
}