1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
use thiserror::Error;
#[derive(Error, Debug)]
pub enum InternalError {
    GroupChunkReadAsDataChunk,
    DataChunkReadAsGroupChunk,
    OutOfBounds,
    Unreachable,
    InvalidChunkBy,
}
impl std::fmt::Display for InternalError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            InternalError::GroupChunkReadAsDataChunk => write!(f, "GroupChunk read as data."),
            InternalError::DataChunkReadAsGroupChunk => write!(f, "DataChunk read as group."),
            InternalError::OutOfBounds => write!(f, "Out of bounds access."),
            InternalError::Unreachable => write!(f, "Unreachable code was reached."),
            InternalError::InvalidChunkBy => write!(
                f,
                "Attempted to chunk data in vector that is not compatible to the target type."
            ),
        }
    }
}

#[derive(Error, Debug)]
pub enum ParsingError {
    #[error("Invalid Alembic File")]
    InvalidAlembicFile,
    #[error("Unsupported Alembic File")]
    UnsupportedAlembicFile,

    #[error("Cannot parse schema on object structure")]
    IncompatibleSchema,

    #[error(transparent)]
    FromUtf8Error(#[from] std::string::FromUtf8Error),
}

#[derive(Error, Debug)]
pub enum UserError {
    OutOfBounds,
    InvalidParameter,
}
impl std::fmt::Display for UserError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            UserError::OutOfBounds => write!(f, "Out of bounds"),
            UserError::InvalidParameter => write!(f, "Invalid parameter"),
        }
    }
}

#[derive(Error, Debug)]
pub enum OgawaError {
    #[error("Internal error")]
    InternalError(#[from] InternalError),

    #[error("Parsing error")]
    ParsingError(#[from] ParsingError),

    #[error("User error")]
    UserError(#[from] UserError),

    #[error("I/O error")]
    IoError(#[from] std::io::Error),

    #[error(transparent)]
    Other(#[from] anyhow::Error),
}
pub type Result<V, E = OgawaError> = ::std::result::Result<V, E>;