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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
use error_chain::error_chain;

error_chain! {
    types {
        BencodeParseError, BencodeParseErrorKind, BencodeParseResultExt, BencodeParseResult;
    }

    errors {
        BytesEmpty {
            pos: usize
         } {
            description("Incomplete Number Of Bytes")
            display("Incomplete Number Of Bytes At {:?}", pos)
        }
        InvalidByte {
            pos: usize
         } {
            description("Invalid Byte Found")
            display("Invalid Byte Found At {:?}", pos)
        }
        InvalidIntNoDelimiter {
            pos: usize
         } {
            description("Invalid Integer Found With No Delimiter")
            display("Invalid Integer Found With No Delimiter At {:?}", pos)
        }
        InvalidIntNegativeZero {
            pos: usize
         } {
            description("Invalid Integer Found As Negative Zero")
            display("Invalid Integer Found As Negative Zero At {:?}", pos)
        }
        InvalidIntZeroPadding {
            pos: usize
         } {
            description("Invalid Integer Found With Zero Padding")
            display("Invalid Integer Found With Zero Padding At {:?}", pos)
        }
        InvalidIntParseError {
            pos: usize
         } {
            description("Invalid Integer Found To Fail Parsing")
            display("Invalid Integer Found To Fail Parsing At {:?}", pos)
        }
        InvalidKeyOrdering {
            pos: usize,
            key: Vec<u8>
         } {
            description("Invalid Dictionary Key Ordering Found")
            display("Invalid Dictionary Key Ordering Found At {:?} For Key {:?}", pos, key)
        }
        InvalidKeyDuplicates {
            pos: usize,
            key: Vec<u8>
         } {
            description("Invalid Dictionary Duplicate Keys Found")
            display("Invalid Dictionary Key Found At {:?} For Key {:?}", pos, key)
        }
        InvalidLengthNegative {
            pos: usize
         } {
            description("Invalid Byte Length Found As Negative")
            display("Invalid Byte Length Found As Negative At {:?}", pos)
        }
        InvalidLengthOverflow {
            pos: usize
         } {
            description("Invalid Byte Length Found To Overflow Buffer Length")
            display("Invalid Byte Length Found To Overflow Buffer Length At {:?}", pos)
        }
        InvalidRecursionExceeded {
            pos: usize,
            max: usize
        } {
            description("Invalid Recursion Limit Exceeded")
            display("Invalid Recursion Limit Exceeded At {:?} For Limit {:?}", pos, max)
        }
    }
}

error_chain! {
    types {
        BencodeConvertError, BencodeConvertErrorKind, BencodeConvertResultExt, BencodeConvertResult;
    }

    errors {
        MissingKey {
            key: Vec<u8>
         } {
            description("Missing Key In Bencode")
            display("Missing Key In Bencode For {:?}", key)
        }
        WrongType {
            key: Vec<u8>,
            expected_type: String
         } {
            description("Wrong Type In Bencode")
            display("Wrong Type In Bencode For {:?} Expected Type {}", key, expected_type)
        }
    }
}