use std::fmt;
#[derive(Debug, Clone)]
pub enum Error {
Native { code: i32, message: String },
PasswordRequired { message: String },
PasswordIncorrect { message: String },
}
impl Error {
#[must_use]
pub fn from_status(code: i32, message: String) -> Self {
match code {
crate::XL_STATUS_PASSWORD_REQUIRED => Error::PasswordRequired { message },
crate::XL_STATUS_PASSWORD_INCORRECT => Error::PasswordIncorrect { message },
_ => Error::Native { code, message },
}
}
#[must_use]
pub fn code(&self) -> i32 {
match self {
Error::Native { code, .. } => *code,
Error::PasswordRequired { .. } => crate::XL_STATUS_PASSWORD_REQUIRED,
Error::PasswordIncorrect { .. } => crate::XL_STATUS_PASSWORD_INCORRECT,
}
}
#[must_use]
pub fn message(&self) -> &str {
match self {
Error::Native { message, .. }
| Error::PasswordRequired { message }
| Error::PasswordIncorrect { message } => message,
}
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "ExcelReader error {}: {}", self.code(), self.message())
}
}
impl std::error::Error for Error {}