epubparse/
errors.rs

1use std::{io, string};
2
3use thiserror::Error;
4
5/// The top-level Error type that captures all failure scenarios
6/// of the epub -> book conversion
7#[derive(Error, Debug)]
8pub enum ParseError {
9    #[error("File error")]
10    FileError(#[from] io::Error),
11    #[error("Error in underlying Zip archive")]
12    ZipError(#[from] zip::result::ZipError),
13    #[error("Invalid UTF8")]
14    UTF8Error(#[from] string::FromUtf8Error),
15    #[error(transparent)]
16    EpubError(#[from] MalformattedEpubError),
17}
18
19/// Failure scenarios for malformatted epub file that is a valid zip file
20#[derive(Error, Debug)]
21pub enum MalformattedEpubError {
22    #[error("Malformatted/missing container.xml file")]
23    MalformattedContainer,
24    #[error("Malformatted content.opf file")]
25    MalformattedContentOpf,
26    #[error("Malformatted toc.ncx file, err: `{0}`")]
27    MalformattedTocNcx(String),
28    #[error("Malformatted manifest or missing resources")]
29    MalformattedManifest,
30    #[error("Could not process HTML resource, file: `{0}`, error: `{1}`")]
31    MalformattedHTML(String, xmltree::ParseError),
32}