use thiserror::Error;
pub type Result<T> = std::result::Result<T, ExcelError>;
#[derive(Error, Debug)]
pub enum ExcelError {
#[error("Failed to read Excel file: {0}")]
ReadError(String),
#[error("Failed to write Excel file: {0}")]
WriteError(String),
#[error("Sheet '{sheet}' not found. Available sheets: {available}")]
SheetNotFound { sheet: String, available: String },
#[error("Failed to write row {row} to sheet '{sheet}': {source}")]
WriteRowError {
row: u32,
sheet: String,
#[source]
source: Box<ExcelError>,
},
#[error("Invalid cell reference: {0}")]
InvalidCell(String),
#[error("IO error: {0}")]
IoError(#[from] std::io::Error),
#[error("Calamine error: {0}")]
CaliamineError(String),
#[error("Invalid format: {0}")]
InvalidFormat(String),
#[error("Feature not supported: {0}")]
NotSupported(String),
#[error("Invalid state: {0}")]
InvalidState(String),
#[error("File not found: {0}")]
FileNotFound(String),
#[error("ZIP error: {0}")]
ZipError(String),
}
impl From<s_zip::SZipError> for ExcelError {
fn from(err: s_zip::SZipError) -> Self {
match err {
s_zip::SZipError::Io(e) => ExcelError::IoError(e),
s_zip::SZipError::InvalidFormat(msg) => ExcelError::InvalidFormat(msg),
s_zip::SZipError::EntryNotFound(name) => {
ExcelError::ReadError(format!("ZIP entry not found: {}", name))
}
s_zip::SZipError::UnsupportedCompression(method) => {
ExcelError::NotSupported(format!("Unsupported compression method: {}", method))
}
}
}
}