use std::io;
use thiserror::Error;
pub type Result<T> = std::result::Result<T, CubeError>;
#[derive(Error, Debug)]
pub enum CubeError {
#[error("I/O error: {0}")]
Io(#[from] io::Error),
#[error("Failed to parse number: {0}")]
ParseFloat(#[from] std::num::ParseFloatError),
#[error("Failed to parse integer: {0}")]
ParseInt(#[from] std::num::ParseIntError),
#[error("Invalid file format: {0}")]
InvalidFormat(String),
#[error("Unknown or repeated keyword: {0}")]
UnknownOrRepeatedKeyword(String),
#[error("Title missing quote")]
TitleMissingQuote,
#[error("Domain bounds reversed: min >= max")]
DomainBoundsReversed,
#[error("LUT size out of range: {size}, expected: {min}-{max}")]
LutSizeOutOfRange { size: usize, min: usize, max: usize },
#[error("Could not parse table data: {0}")]
CouldNotParseTableData(String),
#[error("Premature end of file")]
PrematureEndOfFile,
#[error("Tried Invalid channel images on this LUT")]
InvalidChannel,
#[error("Line too long: {len} bytes (max: 250)")]
LineTooLong { len: usize },
#[error("Unsupported LUT type: {0}")]
UnsupportedLutType(String),
#[error("Image processing error: {0}")]
ImageProcessingError(String),
#[error("Invalid image dimensions")]
InvalidDimensions,
#[error("Index out of bounds: {index} >= {len}")]
IndexOutOfBounds { index: usize, len: usize },
}
impl CubeError {
pub fn is_io_error(&self) -> bool {
matches!(self, CubeError::Io(_))
}
pub fn is_parse_error(&self) -> bool {
matches!(
self,
CubeError::ParseFloat(_)
| CubeError::ParseInt(_)
| CubeError::InvalidFormat(_)
| CubeError::CouldNotParseTableData(_)
)
}
pub fn is_format_error(&self) -> bool {
matches!(
self,
CubeError::UnknownOrRepeatedKeyword(_)
| CubeError::TitleMissingQuote
| CubeError::DomainBoundsReversed
| CubeError::LutSizeOutOfRange { .. }
| CubeError::UnsupportedLutType(_)
)
}
}