Skip to main content

grib_reader/
error.rs

1use thiserror::Error;
2
3pub type Result<T> = std::result::Result<T, Error>;
4
5#[derive(Debug, Error)]
6pub enum Error {
7    #[error("I/O error reading {1}: {0}")]
8    Io(#[source] std::io::Error, String),
9
10    #[error("no GRIB messages found in file")]
11    NoMessages,
12
13    #[error("message index {0} not found")]
14    MessageNotFound(usize),
15
16    #[error("unsupported GRIB edition: {0}")]
17    UnsupportedEdition(u8),
18
19    #[error("invalid GRIB message: {0}")]
20    InvalidMessage(String),
21
22    #[error("invalid section {section}: {reason}")]
23    InvalidSection { section: u8, reason: String },
24
25    #[error("invalid section order: {0}")]
26    InvalidSectionOrder(String),
27
28    #[error("unsupported grid definition template: {0}")]
29    UnsupportedGridTemplate(u16),
30
31    #[error("unsupported data representation template: {0}")]
32    UnsupportedDataTemplate(u16),
33
34    #[error("unsupported product definition template: {0}")]
35    UnsupportedProductTemplate(u16),
36
37    #[error("unsupported bitmap indicator: {0}")]
38    UnsupportedBitmapIndicator(u8),
39
40    #[error("unsupported packing width: {0} bits per value")]
41    UnsupportedPackingWidth(u8),
42
43    #[error("unsupported scanning mode: 0b{0:08b}")]
44    UnsupportedScanningMode(u8),
45
46    #[error("data truncated at offset {offset}")]
47    Truncated { offset: u64 },
48
49    #[error("decoded data length mismatch: expected {expected}, got {actual}")]
50    DataLengthMismatch { expected: usize, actual: usize },
51
52    #[error("bitmap indicates missing values but no bitmap section present")]
53    MissingBitmap,
54
55    #[error("{0}")]
56    Other(String),
57}