rustyhdf5_netcdf4/
error.rs1use std::fmt;
4
5#[derive(Debug)]
7pub enum Error {
8 Io(std::io::Error),
10 Hdf5(rustyhdf5::Error),
12 NotNetCDF4(String),
14 DimensionNotFound(String),
16 VariableNotFound(String),
18 GroupNotFound(String),
20 TypeError(String),
22}
23
24impl fmt::Display for Error {
25 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26 match self {
27 Error::Io(e) => write!(f, "I/O error: {e}"),
28 Error::Hdf5(e) => write!(f, "HDF5 error: {e}"),
29 Error::NotNetCDF4(msg) => write!(f, "not a NetCDF-4 file: {msg}"),
30 Error::DimensionNotFound(name) => write!(f, "dimension not found: {name}"),
31 Error::VariableNotFound(name) => write!(f, "variable not found: {name}"),
32 Error::GroupNotFound(name) => write!(f, "group not found: {name}"),
33 Error::TypeError(msg) => write!(f, "type error: {msg}"),
34 }
35 }
36}
37
38impl std::error::Error for Error {
39 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
40 match self {
41 Error::Io(e) => Some(e),
42 Error::Hdf5(e) => Some(e),
43 _ => None,
44 }
45 }
46}
47
48impl From<std::io::Error> for Error {
49 fn from(e: std::io::Error) -> Self {
50 Error::Io(e)
51 }
52}
53
54impl From<rustyhdf5::Error> for Error {
55 fn from(e: rustyhdf5::Error) -> Self {
56 Error::Hdf5(e)
57 }
58}