rs_car_ipfs/single_file/
error.rs1use rs_car::{CarDecodeError, Cid};
2
3#[derive(Debug)]
4pub enum ReadSingleFileError {
5 IoError(std::io::Error),
6 CarDecodeError(CarDecodeError),
7 NotSingleRoot { roots: Vec<Cid> },
8 InvalidUnixFs(String),
9 InvalidUnixFsHash(String),
10 MissingNode(Cid),
11 MaxBufferedData(usize),
12 RootCidIsNotFile,
13 DataNodesNotSorted,
14 PendingLinksAtEOF(Vec<Cid>),
15 PBLinkHasNoHash,
16 InternalError(String),
17}
18
19impl From<CarDecodeError> for ReadSingleFileError {
20 fn from(error: CarDecodeError) -> Self {
21 match error {
22 CarDecodeError::IoError(err) => ReadSingleFileError::IoError(err),
23 err => ReadSingleFileError::CarDecodeError(err),
24 }
25 }
26}
27
28impl From<std::io::Error> for ReadSingleFileError {
29 fn from(error: std::io::Error) -> Self {
30 ReadSingleFileError::IoError(error)
31 }
32}
33
34impl std::fmt::Display for ReadSingleFileError {
35 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
36 write!(f, "{self:?}")
37 }
38}
39
40impl std::error::Error for ReadSingleFileError {
41 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
42 match self {
43 ReadSingleFileError::IoError(err) => Some(err),
44 ReadSingleFileError::CarDecodeError(err) => Some(err),
45 _ => None,
46 }
47 }
48}