1use std::path::PathBuf;
2
3pub type Result<T> = std::result::Result<T, BookyardError>;
4
5#[derive(Debug, thiserror::Error)]
6pub enum BookyardError {
7 #[error("io error at {path}: {source}")]
8 Io {
9 path: PathBuf,
10 source: std::io::Error,
11 },
12
13 #[error("failed to parse TOML at {path}: {source}")]
14 TomlParse {
15 path: PathBuf,
16 source: toml::de::Error,
17 },
18
19 #[error("failed to write TOML: {0}")]
20 TomlWrite(toml::ser::Error),
21
22 #[error("duplicate book id: {0}")]
23 DuplicateBookId(String),
24
25 #[error("unsupported book source: {0}")]
26 UnsupportedBookSource(PathBuf),
27
28 #[error("unsupported book engine: {0}")]
29 UnsupportedBookEngine(String),
30
31 #[error("mdbook build failed for {id} with status {status}")]
32 MdBookBuildFailed { id: String, status: String },
33}
34
35pub(crate) fn io_error(path: impl Into<PathBuf>, source: std::io::Error) -> BookyardError {
36 BookyardError::Io {
37 path: path.into(),
38 source,
39 }
40}