@@ -11,70 +11,110 @@ use crate::rw;
1111
1212use super :: BencodeType ;
1313
14+ /// Errors that can occur while parsing a bencoded value.
1415#[ derive( Debug , Error ) ]
1516pub enum Error {
17+ /// I/O error.
1618 #[ error( "I/O error: {0}" ) ]
1719 Io ( #[ from] io:: Error ) ,
1820
21+ /// R/W error.
1922 #[ error( "R/W error: {0}" ) ]
2023 Rw ( #[ from] rw:: error:: Error ) ,
2124
25+ /// Read byte after peeking does match peeked byte.
26+ ///
27+ /// The main parser peeks one byte ahead to know what kind of bencoded value
28+ /// is being parsed. If the byte read after peeking does not match the
29+ /// peeked byte, it means the input is being consumed somewhere else.
2230 #[ error( "Read byte after peeking does match peeked byte; {0}; {1}" ) ]
2331 ReadByteAfterPeekingDoesMatchPeekedByte ( ReadContext , WriteContext ) ,
2432
33+ /// Unrecognized first byte for new bencoded value.
34+ ///
35+ /// The main parser peeks one byte ahead to know what kind of bencoded value
36+ /// is being parsed. This error is raised when the peeked byte is not a
37+ /// valid first byte for a bencoded value.
2538 #[ error( "Unrecognized first byte for new bencoded value; {0}; {1}" ) ]
2639 UnrecognizedFirstBencodeValueByte ( ReadContext , WriteContext ) ,
2740
2841 // Integers
42+ /// Unexpected byte parsing integer.
43+ ///
44+ /// The main parser parses integers by reading bytes until it finds the
45+ /// end of the integer. This error is raised when the byte read is not a
46+ /// valid byte for an integer bencoded value.
2947 #[ error( "Unexpected byte parsing integer; {0}; {1}" ) ]
3048 UnexpectedByteParsingInteger ( ReadContext , WriteContext ) ,
3149
50+ /// Unexpected end of input parsing integer.
51+ ///
52+ /// The input ends before the integer ends.
3253 #[ error( "Unexpected end of input parsing integer; {0}; {1}" ) ]
3354 UnexpectedEndOfInputParsingInteger ( ReadContext , WriteContext ) ,
3455
56+ /// Leading zeros in integers are not allowed, for example b'i00e'.
3557 #[ error( "Leading zeros in integers are not allowed, for example b'i00e'; {0}; {1}" ) ]
3658 LeadingZerosInIntegersNotAllowed ( ReadContext , WriteContext ) ,
3759
3860 // Strings
61+ /// Invalid string length byte, expected a digit.
62+ ///
63+ /// The string parser found an invalid byte for the string length. The
64+ /// length can only be made of digits (0-9).
3965 #[ error( "Invalid string length byte, expected a digit; {0}; {1}" ) ]
4066 InvalidStringLengthByte ( ReadContext , WriteContext ) ,
4167
68+ /// Unexpected end of input parsing string length.
69+ ///
70+ /// The input ends before the string length ends.
4271 #[ error( "Unexpected end of input parsing string length; {0}; {1}" ) ]
4372 UnexpectedEndOfInputParsingStringLength ( ReadContext , WriteContext ) ,
4473
74+ /// Unexpected end of input parsing string value.
75+ ///
76+ /// The input ends before the string value ends.
4577 #[ error( "Unexpected end of input parsing string value; {0}; {1}" ) ]
4678 UnexpectedEndOfInputParsingStringValue ( ReadContext , WriteContext ) ,
4779
4880 // Lists
81+ /// Unexpected end of input parsing list. Expecting first list item or list end.
4982 #[ error(
5083 "Unexpected end of input parsing list. Expecting first list item or list end; {0}; {1}"
5184 ) ]
5285 UnexpectedEndOfInputExpectingFirstListItemOrEnd ( ReadContext , WriteContext ) ,
5386
87+ /// Unexpected end of input parsing list. Expecting next list item.
5488 #[ error( "Unexpected end of input parsing list. Expecting next list item; {0}; {1}" ) ]
5589 UnexpectedEndOfInputExpectingNextListItem ( ReadContext , WriteContext ) ,
5690
5791 // Dictionaries
92+ /// Unexpected end of input parsing dictionary. Expecting first dictionary field or dictionary end.
5893 #[ error( "Unexpected end of input parsing dictionary. Expecting first dictionary field or dictionary end; {0}; {1}" ) ]
5994 UnexpectedEndOfInputExpectingFirstDictFieldOrEnd ( ReadContext , WriteContext ) ,
6095
96+ /// Unexpected end of input parsing dictionary. Expecting dictionary field value.
6197 #[ error(
6298 "Unexpected end of input parsing dictionary. Expecting dictionary field value; {0}; {1}"
6399 ) ]
64100 UnexpectedEndOfInputExpectingDictFieldValue ( ReadContext , WriteContext ) ,
65101
102+ /// Unexpected end of input parsing dictionary. Expecting dictionary field key or end.
66103 #[ error(
67104 "Unexpected end of input parsing dictionary. Expecting dictionary field key or end; {0}; {1}"
68105 ) ]
69106 UnexpectedEndOfInputExpectingDictFieldKeyOrEnd ( ReadContext , WriteContext ) ,
70107
108+ /// Unexpected end of dictionary. Premature end of dictionary.
71109 #[ error( "Unexpected end of dictionary. Premature end of dictionary; {0}; {1}" ) ]
72110 PrematureEndOfDict ( ReadContext , WriteContext ) ,
73111
112+ /// Expected string for dictionary field key.
74113 #[ error( "Expected string for dictionary field key, but got: {0}, {1}" ) ]
75114 ExpectedStringForDictKeyGot ( BencodeType , ReadContext , WriteContext ) ,
76115
77116 // List and dictionaries
117+ /// Unexpected end of list or dict. No matching start for the list or dict end.
78118 #[ error(
79119 "Unexpected end of list or dict. No matching start for the list or dict end: {0}, {1}"
80120 ) ]
0 commit comments