torrust_tracker_contrib_bencode/
error.rs

1use thiserror::Error;
2
3#[allow(clippy::module_name_repetitions)]
4#[derive(Error, Debug)]
5pub enum BencodeParseError {
6    #[error("Incomplete Number Of Bytes At {pos}")]
7    BytesEmpty { pos: usize },
8
9    #[error("Invalid Byte Found At {pos}")]
10    InvalidByte { pos: usize },
11
12    #[error("Invalid Integer Found With No Delimiter At {pos}")]
13    InvalidIntNoDelimiter { pos: usize },
14
15    #[error("Invalid Integer Found As Negative Zero At {pos}")]
16    InvalidIntNegativeZero { pos: usize },
17
18    #[error("Invalid Integer Found With Zero Padding At {pos}")]
19    InvalidIntZeroPadding { pos: usize },
20
21    #[error("Invalid Integer Found To Fail Parsing At {pos}")]
22    InvalidIntParseError { pos: usize },
23
24    #[error("Invalid Dictionary Key Ordering Found At {pos} For Key {key:?}")]
25    InvalidKeyOrdering { pos: usize, key: Vec<u8> },
26
27    #[error("Invalid Dictionary Key Found At {pos} For Key {key:?}")]
28    InvalidKeyDuplicates { pos: usize, key: Vec<u8> },
29
30    #[error("Invalid Byte Length Found As Negative At {pos}")]
31    InvalidLengthNegative { pos: usize },
32
33    #[error("Invalid Byte Length Found To Overflow Buffer Length At {pos}")]
34    InvalidLengthOverflow { pos: usize },
35
36    #[error("Invalid Recursion Limit Exceeded At {pos} For Limit {max}")]
37    InvalidRecursionExceeded { pos: usize, max: usize },
38}
39
40pub type BencodeParseResult<T> = Result<T, BencodeParseError>;
41
42#[allow(clippy::module_name_repetitions)]
43#[derive(Error, Debug)]
44pub enum BencodeConvertError {
45    #[error("Missing Key In Bencode For {key:?}")]
46    MissingKey { key: Vec<u8> },
47
48    #[error("Wrong Type In Bencode For {key:?} Expected Type {expected_type}")]
49    WrongType { key: Vec<u8>, expected_type: String },
50}
51
52pub type BencodeConvertResult<T> = Result<T, BencodeConvertError>;