Skip to main content

async_hdf5/
error.rs

1use thiserror::Error;
2
3/// Result type for async-hdf5 operations.
4pub type Result<T> = std::result::Result<T, HDF5Error>;
5
6/// Errors that can occur when reading HDF5 files.
7#[derive(Debug, Error)]
8pub enum HDF5Error {
9    /// The file does not have a valid HDF5 signature.
10    #[error("Not an HDF5 file: {hint}")]
11    InvalidSignature {
12        /// Byte offset that was checked.
13        offset: u64,
14        /// Human-readable hint about what was found instead.
15        hint: String,
16    },
17
18    /// The superblock version is not supported.
19    #[error("Unsupported superblock version: {0}")]
20    UnsupportedSuperblockVersion(u8),
21
22    /// The object header version is not supported.
23    #[error("Unsupported object header version: {0}")]
24    UnsupportedObjectHeaderVersion(u8),
25
26    /// The data layout message version is not supported.
27    #[error("Unsupported data layout version: {0}")]
28    UnsupportedDataLayoutVersion(u8),
29
30    /// The datatype class is not supported.
31    #[error("Unsupported datatype class: {0}")]
32    UnsupportedDatatypeClass(u8),
33
34    /// The filter pipeline version is not supported.
35    #[error("Unsupported filter pipeline version: {0}")]
36    UnsupportedFilterPipelineVersion(u8),
37
38    /// The chunk indexing type is not supported.
39    #[error("Unsupported chunk indexing type: {0}")]
40    UnsupportedChunkIndexingType(u8),
41
42    /// The B-tree version is not supported.
43    #[error("Unsupported B-tree version: {0}")]
44    UnsupportedBTreeVersion(u8),
45
46    /// The B-tree signature does not match what was expected.
47    #[error("Invalid B-tree signature: expected {expected}, got {got}")]
48    InvalidBTreeSignature {
49        /// Expected signature string.
50        expected: String,
51        /// Actual signature found.
52        got: String,
53    },
54
55    /// The heap version is not supported.
56    #[error("Unsupported heap version: {0}")]
57    UnsupportedHeapVersion(u8),
58
59    /// The heap signature does not match what was expected.
60    #[error("Invalid heap signature: expected {expected}, got {got}")]
61    InvalidHeapSignature {
62        /// Expected signature string.
63        expected: String,
64        /// Actual signature found.
65        got: String,
66    },
67
68    /// A group member was not found at the given path.
69    #[error("Group member not found: {0}")]
70    NotFound(String),
71
72    /// The path does not point to a group.
73    #[error("Expected group at path: {0}")]
74    NotAGroup(String),
75
76    /// The path does not point to a dataset.
77    #[error("Expected dataset at path: {0}")]
78    NotADataset(String),
79
80    /// The data ended before the expected number of bytes could be read.
81    #[error("Unexpected end of data: needed {needed} bytes, had {available}")]
82    UnexpectedEof {
83        /// Number of bytes needed.
84        needed: usize,
85        /// Number of bytes available.
86        available: usize,
87    },
88
89    /// An undefined address was encountered (unallocated storage).
90    #[error("Undefined address encountered (unallocated storage)")]
91    UndefinedAddress,
92
93    /// The object header signature is invalid.
94    #[error("Invalid object header signature: expected OHDR")]
95    InvalidObjectHeaderSignature,
96
97    /// The link type is not supported.
98    #[error("Unsupported link type: {0}")]
99    UnsupportedLinkType(u8),
100
101    /// The message type is not supported.
102    #[error("Unsupported message type: {0:#06x}")]
103    UnsupportedMessageType(u16),
104
105    /// An I/O error occurred.
106    #[error("I/O error: {0}")]
107    Io(#[from] std::io::Error),
108
109    /// A general error with a descriptive message.
110    #[error("{0}")]
111    General(String),
112
113    /// An object store error occurred.
114    #[cfg(feature = "object_store")]
115    #[error("Object store error: {0}")]
116    ObjectStore(#[from] object_store::Error),
117
118    /// An HTTP request error occurred.
119    #[cfg(feature = "reqwest")]
120    #[error("HTTP error: {0}")]
121    Reqwest(#[from] reqwest::Error),
122}