Skip to main content

forge_ibl_bake/
error.rs

1// SPDX-License-Identifier: MIT OR Apache-2.0
2// forge-ibl-bake ยท deveraux.dev
3//! Typed error for every fallible operation in the bake pipeline.
4//!
5//! `BakeError` is the single error type returned by all public fns. It carries
6//! the originating `std::io::Error` for I/O failures and a `String` message for
7//! format violations. Callers can pattern-match without depending on any external
8//! error crate. PROVEN: the graceful-failure discriminator tests verify each arm.
9
10use std::fmt;
11
12#[derive(Debug)]
13pub enum BakeError {
14    Io(std::io::Error),
15    InvalidHdr(String),
16    InvalidSize(String),
17    UnsupportedFormat(u32),
18}
19
20impl fmt::Display for BakeError {
21    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22        match self {
23            BakeError::Io(e) => write!(f, "I/O error: {e}"),
24            BakeError::InvalidHdr(s) => write!(f, "invalid HDR: {s}"),
25            BakeError::InvalidSize(s) => write!(f, "invalid size: {s}"),
26            BakeError::UnsupportedFormat(n) => write!(f, "unsupported VkFormat: {n}"),
27        }
28    }
29}
30
31impl std::error::Error for BakeError {
32    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
33        match self {
34            BakeError::Io(e) => Some(e),
35            _ => None,
36        }
37    }
38}
39
40impl From<std::io::Error> for BakeError {
41    fn from(e: std::io::Error) -> Self {
42        BakeError::Io(e)
43    }
44}