use std::path::PathBuf;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum BookifyError {
#[error("PDF processing error: {0}")]
PdfError(#[from] lopdf::Error),
#[error("IO error (file: {path}): {source}")]
IoError {
#[source]
source: std::io::Error,
path: PathBuf,
},
#[error("PDF file not found: {path}")]
PdfFileNotFound { path: PathBuf },
#[error("Invalid PDF format: {message}")]
InvalidPdfFormat { message: String },
#[error("PDF processing failed: {operation} - {details}")]
PdfProcessingFailed { operation: String, details: String },
#[error("Other error: {context} - {message}")]
Other { context: String, message: String },
}
impl BookifyError {
pub fn io_error(source: std::io::Error, path: impl Into<PathBuf>) -> Self {
Self::IoError {
source,
path: path.into(),
}
}
pub fn pdf_file_not_found(path: impl Into<PathBuf>) -> Self {
Self::PdfFileNotFound { path: path.into() }
}
pub fn invalid_pdf_format(message: impl Into<String>) -> Self {
Self::InvalidPdfFormat {
message: message.into(),
}
}
pub fn pdf_processing_failed(operation: impl Into<String>, details: impl Into<String>) -> Self {
Self::PdfProcessingFailed {
operation: operation.into(),
details: details.into(),
}
}
pub fn other(context: impl Into<String>, message: impl Into<String>) -> Self {
Self::Other {
context: context.into(),
message: message.into(),
}
}
}