Johannes Hofmann 7 лет назад
Родитель
Сommit
54145beb47
3 измененных файлов: 26 добавлений и 9 удалений
  1. 1
    2
      src/block.rs
  2. 24
    6
      src/error.rs
  3. 1
    1
      src/lib.rs

+ 1
- 2
src/block.rs Просмотреть файл

@@ -370,9 +370,8 @@ impl<'a> ExactSizeIterator for GroupRelationIter<'a> {}
370 370
 
371 371
 pub(crate) fn str_from_stringtable(block: &osmformat::PrimitiveBlock, index: usize) -> Result<&str> {
372 372
     if let Some(vec) = block.get_stringtable().get_s().get(index) {
373
-        //TODO at location to ErrorKind::Utf8
374 373
         std::str::from_utf8(vec)
375
-            .map_err(|e| new_error(ErrorKind::Utf8(e)))
374
+            .map_err(|e| new_error(ErrorKind::StringtableUtf8{err: e, index}))
376 375
     } else {
377 376
         Err(new_error(ErrorKind::StringtableIndexOutOfBounds{index}))
378 377
     }

+ 24
- 6
src/error.rs Просмотреть файл

@@ -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
             },

+ 1
- 1
src/lib.rs Просмотреть файл

@@ -87,7 +87,7 @@ pub use blob::*;
87 87
 pub use block::*;
88 88
 pub use dense::*;
89 89
 pub use elements::*;
90
-pub use error::{Error, ErrorKind, Result};
90
+pub use error::{BlobError, Error, ErrorKind, Result};
91 91
 pub use mmap_blob::*;
92 92
 pub use reader::*;
93 93