pbrt/src/utils/error.rs

81 lines
2.1 KiB
Rust

use image_rs::{ImageError as IError, error};
use std::fmt;
use thiserror::Error;
use crate::image::PixelFormat;
#[derive(Error, Debug)]
pub enum LlsError {
SingularMatrix,
}
#[derive(Error, Debug, Clone, PartialEq, Eq)]
pub enum InversionError {
SingularMatrix,
EmptyMatrix,
}
impl fmt::Display for LlsError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
LlsError::SingularMatrix => write!(f, "Matrix is singular and cannot be inverted."),
}
}
}
impl fmt::Display for InversionError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
InversionError::SingularMatrix => {
write!(f, "Matrix is singular and cannot be inverted.")
}
InversionError::EmptyMatrix => write!(f, "Matrix is empty and cannot be inverted."),
}
}
}
#[derive(Error, Debug)]
pub enum ImageError {
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
#[error("Image file error: {0}")]
Image(#[from] IError),
#[error("EXR file error: {0}")]
Exr(#[from] exr::error::Error),
#[error("QOI file error: {0}")]
Qoi(String),
#[error("Pixel format error: {0}")]
PixelFormat(#[from] PixelFormatError),
#[error("Unsupported operation: {0}")]
Unsupported(String),
#[error("Mismatched dimensions or channels: {0}")]
Mismatch(String),
#[error("Channel '{0}' not found in image")]
ChannelNotFound(String),
}
/// Describes an error related to an unexpected or unsupported pixel format.
#[derive(Error, Debug, Clone, PartialEq, Eq)]
pub enum PixelFormatError {
#[error("Unsupported operation '{operation}' for pixel format {actual:?}. Reason: {reason}")]
UnsupportedOperation {
operation: String,
actual: PixelFormat,
reason: String,
},
#[error("Invalid conversion from pixel format {from:?} to {to:?}.")]
InvalidConversion { from: PixelFormat, to: PixelFormat },
#[error(
"Internal invariant violated: image format is {expected:?} but pixel data is of a different type."
)]
InternalFormatMismatch { expected: PixelFormat },
}