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
//! Error/result types

use std::io;

use ndarray::ShapeError;
use thiserror::Error;

/// `Result` type alias for operations that can lead to I/O errors.
pub type Result<T> = ::std::result::Result<T, Error>;

/// finalfusion errors
#[non_exhaustive]
#[derive(Debug, Error)]
pub enum Error {
    /// Invalid file format.
    #[error("Invalid file format {0}")]
    Format(String),

    /// `ndarray` shape error.
    #[error(transparent)]
    Shape(#[from] ShapeError),

    #[error("{desc:?}: {error:?}")]
    Io { desc: String, error: io::Error },

    #[error("Unknown chunk identifier {0}")]
    UnknownChunkIdentifier(u32),
}

impl Error {
    pub fn io_error(desc: impl Into<String>, error: io::Error) -> Self {
        Error::Io {
            desc: desc.into(),
            error,
        }
    }
}