Skip to main content

zenavif/
error.rs

1//! Error types for zenavif
2
3use enough::StopReason;
4
5/// Error type for zenavif decoding operations
6#[derive(Debug, thiserror::Error)]
7#[non_exhaustive]
8pub enum Error {
9    /// AVIF container parsing error
10    #[error("AVIF parse error: {0}")]
11    Parse(#[from] zenavif_parse::Error),
12
13    /// AV1 decode error from rav1d
14    #[error("AV1 decode error {code}: {msg}")]
15    Decode {
16        /// rav1d error code
17        code: i32,
18        /// Error description
19        msg: &'static str,
20    },
21
22    /// YUV to RGB color conversion error
23    #[error("Color conversion error: {0}")]
24    ColorConversion(#[from] yuv::YuvError),
25
26    /// AV1 encode error
27    #[error("AV1 encode error: {0}")]
28    Encode(String),
29
30    /// Unsupported feature
31    #[error("Unsupported: {0}")]
32    Unsupported(&'static str),
33
34    /// Image dimensions exceed configured limit
35    #[error("Image too large: {width}x{height}")]
36    ImageTooLarge {
37        /// Image width
38        width: u32,
39        /// Image height
40        height: u32,
41    },
42
43    /// A resource limit was exceeded (memory, input size, output size, etc.)
44    #[error("Resource limit exceeded: {0}")]
45    ResourceLimit(String),
46
47    /// Memory allocation failed
48    #[error("Out of memory")]
49    OutOfMemory,
50
51    /// Operation was cancelled via Stop trait
52    #[error("Operation cancelled: {0:?}")]
53    Cancelled(StopReason),
54
55    /// Unsupported codec operation
56    #[cfg(feature = "zencodec")]
57    #[error(transparent)]
58    UnsupportedOperation(#[from] zencodec::UnsupportedOperation),
59}
60
61impl From<StopReason> for Error {
62    fn from(reason: StopReason) -> Self {
63        Error::Cancelled(reason)
64    }
65}
66
67/// Result type for zenavif operations with location tracking
68pub type Result<T, E = whereat::At<Error>> = core::result::Result<T, E>;