lib/result.rs
1//! Defines the result and error types for this crate.
2
3/// A generic result type.
4pub type Result<T> = std::result::Result<T, Error>;
5
6/// An enum representing all possible library errors.
7#[derive(Debug, thiserror::Error)]
8pub enum Error {
9 /// Error returned when the default Apple Books database cannot be found.
10 #[error("missing default Apple Books databases")]
11 MissingDefaultDatabase,
12
13 /// Error returned when there are issues connecting to a database.
14 #[error("unable to connect to '{name}*.sqlite' at {path}")]
15 DatabaseConnection {
16 /// The basename of the database: `BKLibrary` or `AEAnnotation`.
17 name: String,
18 /// The path to the database.
19 path: String,
20 },
21
22 /// Error returned when the currently installed version of Apple Books for macOS is unsupported.
23 ///
24 /// This most likely means that the database schema is different than the one the query has been
25 /// designed for. In that case, the currently installed version of Apple Books is considered
26 /// unsupported.
27 #[error("unsupported version of Apple Books for macOS: {version}")]
28 UnsupportedMacosVersion {
29 /// The currently installed Apple Books for macOS version number.
30 version: String,
31 /// The source error string.
32 error: String,
33 },
34
35 /// Error returned when the currently installed version of Apple Books for iOS is unsupported.
36 ///
37 /// This most likely means that the plist schema is different than the one used for
38 /// deserialization. In that case, the currently installed version of Apple Books for iOS is
39 /// considered unsupported.
40 // TODO: Is there a way to retrieve the iOS version from the device?
41 #[error("unsupported version of Apple Books for iOS: {error}")]
42 UnsupportedIosVersion {
43 /// The source error string.
44 error: String,
45 },
46
47 /// Error returned when a syntax error is detected in how a template's config block is defined.
48 /// This does not include YAML syntax error.
49 #[error("cannot read config for: {path}")]
50 InvalidTemplateConfig {
51 /// The partial path to the template e.g. `nested/template.md`.
52 path: String,
53 },
54
55 /// Error returned when a requested template-group does not exist.
56 #[error("no template-group named: '{name}'")]
57 NonexistentTemplateGroup {
58 /// The name of the template-group.
59 name: String,
60 },
61
62 /// Error returned if [`tera`][tera] encounters any errors.
63 ///
64 /// [tera]: https://docs.rs/tera/latest/tera/
65 #[error(transparent)]
66 InvalidTemplate(#[from] tera::Error),
67
68 /// Error returned if [`serde_json`][serde-json] encounters any errors during serialization.
69 ///
70 /// [serde-json]: https://docs.rs/serde_json/latest/serde_json/
71 #[error(transparent)]
72 JsonSerializationError(#[from] serde_json::Error),
73
74 /// Error returned if [`plist`][plist] encounters any errors during deserialization.
75 ///
76 /// [plist]: https://docs.rs/plist/latest/plist/
77 #[error(transparent)]
78 PlistDeserializationError(#[from] plist::Error),
79
80 /// Error returned if [`serde_yaml`][serde-yaml] encounters any errors during deserialization.
81 ///
82 /// [serde-yaml]: https://docs.rs/serde_yaml/latest/serde_yaml/
83 #[error(transparent)]
84 YamlDeserializationError(#[from] serde_yaml_ng::Error),
85
86 /// Error returned if any other IO errors are encountered.
87 #[error(transparent)]
88 IoError(#[from] std::io::Error),
89}