|
|
@@ -43,10 +43,16 @@ impl Error {
|
|
43
|
43
|
/// The specific type of an error.
|
|
44
|
44
|
#[derive(Debug)]
|
|
45
|
45
|
pub enum ErrorKind {
|
|
|
46
|
+ /// An error for I/O operations.
|
|
46
|
47
|
Io(io::Error),
|
|
|
48
|
+ /// An error that occurs when decoding a protobuf message.
|
|
47
|
49
|
Protobuf{err: ProtobufError, location: &'static str},
|
|
48
|
|
- Utf8(Utf8Error),
|
|
|
50
|
+ /// The stringtable contains an entry at `index` that could not be decoded to a valid UTF-8
|
|
|
51
|
+ /// string.
|
|
|
52
|
+ StringtableUtf8{err: Utf8Error, index: usize},
|
|
|
53
|
+ /// An element contains an out-of-bounds index to the stringtable.
|
|
49
|
54
|
StringtableIndexOutOfBounds{index: usize},
|
|
|
55
|
+ /// An error that occurs when decoding `Blob`s.
|
|
50
|
56
|
Blob(BlobError),
|
|
51
|
57
|
|
|
52
|
58
|
//TODO add UnexpectedPrimitiveBlock
|
|
|
@@ -63,9 +69,19 @@ pub enum ErrorKind {
|
|
63
|
69
|
/// An error that occurs when decoding a blob.
|
|
64
|
70
|
#[derive(Debug)]
|
|
65
|
71
|
pub enum BlobError {
|
|
|
72
|
+ /// Header size could not be decoded to a u32.
|
|
66
|
73
|
InvalidHeaderSize,
|
|
67
|
|
- HeaderTooBig{size: u64},
|
|
68
|
|
- MessageTooBig{size: u64},
|
|
|
74
|
+ /// Blob header is bigger than [`MAX_BLOB_HEADER_SIZE`](blob/MAX_BLOB_HEADER_SIZE.v.html).
|
|
|
75
|
+ HeaderTooBig{
|
|
|
76
|
+ /// Blob header size in bytes.
|
|
|
77
|
+ size: u64
|
|
|
78
|
+ },
|
|
|
79
|
+ /// Blob content is bigger than [`MAX_BLOB_MESSAGE_SIZE`](blob/MAX_BLOB_MESSAGE_SIZE.v.html).
|
|
|
80
|
+ MessageTooBig{
|
|
|
81
|
+ /// Blob content size in bytes.
|
|
|
82
|
+ size: u64
|
|
|
83
|
+ },
|
|
|
84
|
+ /// The blob is empty because the `raw` and `zlib-data` fields are missing.
|
|
69
|
85
|
Empty,
|
|
70
|
86
|
/// Hints that destructuring should not be exhaustive.
|
|
71
|
87
|
#[doc(hidden)]
|
|
|
@@ -90,7 +106,7 @@ impl StdError for Error {
|
|
90
|
106
|
match *self.0 {
|
|
91
|
107
|
ErrorKind::Io(ref err) => err.description(),
|
|
92
|
108
|
ErrorKind::Protobuf{ref err, ..} => err.description(),
|
|
93
|
|
- ErrorKind::Utf8(ref err) => err.description(),
|
|
|
109
|
+ ErrorKind::StringtableUtf8{ref err, ..} => err.description(),
|
|
94
|
110
|
ErrorKind::StringtableIndexOutOfBounds{..} => "stringtable index out of bounds",
|
|
95
|
111
|
ErrorKind::Blob(BlobError::InvalidHeaderSize) => "blob header size could not be decoded",
|
|
96
|
112
|
ErrorKind::Blob(BlobError::HeaderTooBig{..}) => "blob header is too big",
|
|
|
@@ -104,7 +120,7 @@ impl StdError for Error {
|
|
104
|
120
|
match *self.0 {
|
|
105
|
121
|
ErrorKind::Io(ref err) => Some(err),
|
|
106
|
122
|
ErrorKind::Protobuf{ref err, ..} => Some(err),
|
|
107
|
|
- ErrorKind::Utf8(ref err) => Some(err),
|
|
|
123
|
+ ErrorKind::StringtableUtf8{ref err, ..} => Some(err),
|
|
108
|
124
|
ErrorKind::StringtableIndexOutOfBounds{..} => None,
|
|
109
|
125
|
ErrorKind::Blob(BlobError::InvalidHeaderSize) => None,
|
|
110
|
126
|
ErrorKind::Blob(BlobError::HeaderTooBig{..}) => None,
|
|
|
@@ -122,7 +138,9 @@ impl fmt::Display for Error {
|
|
122
|
138
|
ErrorKind::Protobuf{ref err, location} => {
|
|
123
|
139
|
write!(f, "protobuf error at '{}': {}", location, err)
|
|
124
|
140
|
},
|
|
125
|
|
- ErrorKind::Utf8(ref err) => err.fmt(f),
|
|
|
141
|
+ ErrorKind::StringtableUtf8{ref err, index} => {
|
|
|
142
|
+ write!(f, "invalid UTF-8 at string table index {}: {}", index, err)
|
|
|
143
|
+ }
|
|
126
|
144
|
ErrorKind::StringtableIndexOutOfBounds { index } => {
|
|
127
|
145
|
write!(f, "stringtable index out of bounds: {}", index)
|
|
128
|
146
|
},
|