blob: 28233e869f99a5541c688d0a61280e63a15db7c1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
use super::*;
use num_enum::TryFromPrimitiveError;
use thiserror::Error;
#[derive(Error, Debug)]
pub enum Error {
#[error("io error: {0}")]
IoError(#[from] std::io::Error),
#[error("invalid protocol ID: {0}")]
InvalidProtoId(u32),
#[error("invalid channel: {0}")]
InvalidChannel(u8),
#[error("invalid type: {0}")]
InvalidType(u8),
#[error("invalid control type: {0}")]
InvalidCtlType(u8),
#[error("peer ID already set")]
PeerIDAlreadySet,
#[error("chunk index {0} bigger than chunk count {1}")]
InvalidChunkIndex(usize, usize),
#[error("chunk count changed from {0} to {1}")]
InvalidChunkCount(usize, usize),
#[error("remote disconnected (timeout = {0})")]
RemoteDisco(bool),
#[error("local disconnected")]
LocalDisco,
}
impl From<TryFromPrimitiveError<PktType>> for Error {
fn from(err: TryFromPrimitiveError<PktType>) -> Self {
Self::InvalidType(err.number)
}
}
impl From<TryFromPrimitiveError<CtlType>> for Error {
fn from(err: TryFromPrimitiveError<CtlType>) -> Self {
Self::InvalidCtlType(err.number)
}
}
|