X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Ferror.rs;h=f434804e1e6fb9315801ae2b56b13fbdbbd346a0;hb=944c16adfb83976149701086e20146797d4330df;hp=9b84ace0f55984077a0b9eaa1748e47f060991bf;hpb=f160c0fa78744b337f03b619e2d8b61ed916402b;p=mt_rudp.git diff --git a/src/error.rs b/src/error.rs index 9b84ace..f434804 100644 --- a/src/error.rs +++ b/src/error.rs @@ -7,10 +7,12 @@ use tokio::sync::mpsc::error::SendError; pub enum Error { IoError(io::Error), InvalidProtoId(u32), - InvalidPeerID, InvalidChannel(u8), InvalidType(u8), InvalidCtlType(u8), + PeerIDAlreadySet, + InvalidChunkIndex(usize, usize), + InvalidChunkCount(usize, usize), RemoteDisco, LocalDisco, } @@ -35,24 +37,26 @@ impl From> for Error { impl From> for Error { fn from(_err: SendError) -> Self { - Self::LocalDisco // technically not a disconnect but a local drop + Self::LocalDisco } } impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { use Error::*; - write!(f, "RUDP Error: ")?; + write!(f, "RUDP error: ")?; match self { - IoError(err) => write!(f, "IO Error: {}", err), - InvalidProtoId(id) => write!(f, "Invalid Protocol ID: {id}"), - InvalidPeerID => write!(f, "Invalid Peer ID"), - InvalidChannel(ch) => write!(f, "Invalid Channel: {ch}"), - InvalidType(tp) => write!(f, "Invalid Type: {tp}"), - InvalidCtlType(tp) => write!(f, "Invalid Control Type: {tp}"), - RemoteDisco => write!(f, "Remote Disconnected"), - LocalDisco => write!(f, "Local Disconnected"), + IoError(err) => write!(f, "IO error: {}", err), + InvalidProtoId(id) => write!(f, "invalid protocol ID: {id}"), + InvalidChannel(ch) => write!(f, "invalid channel: {ch}"), + InvalidType(tp) => write!(f, "invalid type: {tp}"), + InvalidCtlType(tp) => write!(f, "invalid control type: {tp}"), + PeerIDAlreadySet => write!(f, "peer ID already set"), + InvalidChunkIndex(i, n) => write!(f, "chunk index {i} bigger than chunk count {n}"), + InvalidChunkCount(o, n) => write!(f, "chunk count changed from {o} to {n}"), + RemoteDisco => write!(f, "remote disconnected"), + LocalDisco => write!(f, "local disconnected"), } } }