use std::io;
use thiserror::Error;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, Error)]
pub enum Error {
#[error("I/O error: {0}")]
Io(#[from] io::Error),
#[error("zip error: {0}")]
Zip(#[from] zip::result::ZipError),
#[error("xml error: {0}")]
Xml(String),
#[error("OPC error: {0}")]
Opc(String),
#[error("OOXML error: {0}")]
Oxml(String),
#[error("not found: {0}")]
NotFound(String),
#[error("index out of range: {0}")]
IndexOutOfRange(usize),
#[error("not implemented: {0}")]
NotImplemented(&'static str),
#[error("encryption error: {0}")]
Encryption(String),
#[error("ppt97 error: {0}")]
Ppt97(String),
#[error("{0}")]
Other(String),
}
impl Error {
pub fn opc<S: Into<String>>(msg: S) -> Self {
Error::Opc(msg.into())
}
pub fn oxml<S: Into<String>>(msg: S) -> Self {
Error::Oxml(msg.into())
}
pub fn not_implemented(feature: &'static str) -> Self {
Error::NotImplemented(feature)
}
pub fn encryption<S: Into<String>>(msg: S) -> Self {
Error::Encryption(msg.into())
}
pub fn ppt97<S: Into<String>>(msg: S) -> Self {
Error::Ppt97(msg.into())
}
}
impl From<ooxml_core::Error> for Error {
fn from(e: ooxml_core::Error) -> Self {
match e {
ooxml_core::Error::Io(v) => Error::Io(v),
ooxml_core::Error::Zip(v) => Error::Zip(v),
ooxml_core::Error::Xml(s) => Error::Xml(s),
ooxml_core::Error::Opc(s) => Error::Opc(s),
ooxml_core::Error::Oxml(s) => Error::Oxml(s),
ooxml_core::Error::NotFound(s) => Error::NotFound(s),
ooxml_core::Error::IndexOutOfRange(i) => Error::IndexOutOfRange(i),
ooxml_core::Error::NotImplemented(f) => Error::NotImplemented(f),
ooxml_core::Error::Encryption(s) => Error::Encryption(s),
ooxml_core::Error::Other(s) => Error::Other(s),
}
}
}