Skip to main content

ff_render/
error.rs

1use ff_format::{ErrorSeverity, MediaError};
2
3#[derive(Debug, thiserror::Error)]
4pub enum RenderError {
5    #[error("GPU device creation failed: {message}")]
6    DeviceCreation { message: String },
7
8    #[error("shader compile failed: {message}")]
9    ShaderCompile { message: String },
10
11    #[error("texture creation failed: width={width} height={height} reason={reason}")]
12    TextureCreation {
13        width: u32,
14        height: u32,
15        reason: String,
16    },
17
18    #[error("composite failed: {message}")]
19    Composite { message: String },
20
21    #[error("lut load failed: path={path} reason={reason}")]
22    LutLoad { path: String, reason: String },
23
24    #[error("unsupported pixel format: {format}")]
25    UnsupportedFormat { format: String },
26
27    #[error("gpu operation timed out: {operation}")]
28    GpuTimeout { operation: String },
29
30    #[error("ffmpeg error: {message} (code={code})")]
31    Ffmpeg { code: i32, message: String },
32
33    #[error("io error: {0}")]
34    Io(#[from] std::io::Error),
35}
36
37impl MediaError for RenderError {
38    fn severity(&self) -> ErrorSeverity {
39        match self {
40            Self::Ffmpeg { .. } | Self::UnsupportedFormat { .. } => ErrorSeverity::Other,
41            Self::DeviceCreation { .. }
42            | Self::ShaderCompile { .. }
43            | Self::TextureCreation { .. }
44            | Self::Composite { .. }
45            | Self::LutLoad { .. }
46            | Self::GpuTimeout { .. }
47            | Self::Io(_) => ErrorSeverity::Fatal,
48        }
49    }
50}
51
52#[cfg(test)]
53mod tests {
54    use super::*;
55
56    #[test]
57    fn render_io_should_be_fatal() {
58        let e: RenderError = std::io::Error::other("x").into();
59        assert!(e.is_fatal() && !e.is_recoverable());
60    }
61
62    #[test]
63    fn render_ffmpeg_should_be_other() {
64        let e = RenderError::Ffmpeg {
65            code: -22,
66            message: "x".into(),
67        };
68        assert!(!e.is_fatal() && !e.is_recoverable());
69    }
70}