Skip to main content

mdbook_epub/
errors.rs

1use mime_guess::mime::FromStrError;
2use std::path::PathBuf;
3use thiserror::Error;
4
5#[derive(Error, Debug)]
6pub enum Error {
7    #[error("Incompatible mdbook version got {0} expected {1}")]
8    IncompatibleVersion(String, String),
9
10    #[error("{0}")]
11    EpubDocCreate(String),
12
13    #[error("Could not parse the template")]
14    TemplateParse,
15
16    #[error("Content file was not found: \'{0}\'")]
17    ContentFileNotFound(String),
18
19    #[error("{0}")]
20    AssetFileNotFound(String),
21
22    #[error("Asset was not a file {0}")]
23    AssetFile(PathBuf),
24
25    #[error("Could not open css file {0}")]
26    CssOpen(PathBuf),
27
28    #[error("Unable to open template {0}")]
29    OpenTemplate(PathBuf),
30
31    #[error("Unable to parse render context")]
32    RenderContext,
33
34    #[error("Failed to {action} '{path}': {source}")]
35    AssetFileIo {
36        action: String,  // string action type: "open", "create", "read", "write"
37        path: PathBuf,
38        source: std::io::Error,
39    },
40
41    #[error("Path error for '{path}': {source}")]
42    AssetPathIo {
43        path: PathBuf,
44        source: std::io::Error,
45    },
46
47    #[error("Unable to open asset")]
48    AssetOpen(#[from] std::io::Error),
49
50    #[error("Failed to find resource file (a root + path?): {0}")]
51    ResourceNotFound(PathBuf),
52
53    #[error("Error reading stylesheet")]
54    StylesheetRead,
55
56    #[error("epubcheck has failed: {0}")]
57    EpubCheck(String),
58
59    #[error(transparent)]
60    AssetOutsideSrcDir(#[from] std::path::StripPrefixError),
61
62    #[error(transparent)]
63    Book(#[from] mdbook_core::errors::Error),
64    #[error(transparent)]
65    Semver(#[from] semver::Error),
66    #[error(transparent)]
67    EpubBuilder(#[from] epub_builder::Error),
68    #[error(transparent)]
69    Render(#[from] handlebars::RenderError),
70    #[error(transparent)]
71    TomlDeser(#[from] toml::de::Error),
72    #[error(transparent)]
73    HttpError(#[from] Box<ureq::Error>),
74    #[error(transparent)]
75    MimeTypeError(#[from] FromStrError),
76
77    #[error("Incorrect book 'title', impossible to create file with name: '{0}'")]
78    EpubBookNameOrPath(String),
79}
80
81impl From<ureq::Error> for Error {
82    fn from(e: ureq::Error) -> Self {
83        Error::HttpError(Box::new(e))
84    }
85}