Skip to main content

netcdf_reader/
error.rs

1/// Errors produced by the NetCDF reader.
2#[derive(Debug, thiserror::Error)]
3pub enum Error {
4    #[error("I/O error: {0}")]
5    Io(#[from] std::io::Error),
6
7    #[error("invalid NetCDF magic bytes")]
8    InvalidMagic,
9
10    #[error("unsupported NetCDF format version {0}")]
11    UnsupportedVersion(u8),
12
13    #[error("variable not found: {0}")]
14    VariableNotFound(String),
15
16    #[error("dimension not found: {0}")]
17    DimensionNotFound(String),
18
19    #[error("attribute not found: {0}")]
20    AttributeNotFound(String),
21
22    #[error("group not found: {0}")]
23    GroupNotFound(String),
24
25    #[error("type mismatch: expected {expected}, got {actual}")]
26    TypeMismatch { expected: String, actual: String },
27
28    #[error("invalid data: {0}")]
29    InvalidData(String),
30
31    #[error("unsupported feature: {0}")]
32    UnsupportedFeature(String),
33
34    #[error(
35        "unexpected end of file at offset {offset}: need {needed} bytes, available {available}"
36    )]
37    UnexpectedEof {
38        offset: u64,
39        needed: u64,
40        available: u64,
41    },
42
43    #[error("HDF5 error: {0}")]
44    #[cfg(feature = "netcdf4")]
45    Hdf5(#[from] hdf5_reader::error::Error),
46
47    #[error("NetCDF-4 support not enabled (enable 'netcdf4' feature)")]
48    Nc4NotEnabled,
49}
50
51pub type Result<T> = std::result::Result<T, Error>;