Skip to main content

archelon_core/
error.rs

1use thiserror::Error;
2
3#[derive(Debug, Error)]
4pub enum Error {
5    #[error("IO error: {0}")]
6    Io(#[from] std::io::Error),
7
8    #[error("Failed to parse frontmatter: {0}")]
9    FrontmatterParse(#[from] serde_yaml::Error),
10
11    #[error("Invalid entry file: {0}")]
12    InvalidEntry(String),
13
14    #[error("no .archelon directory found in current directory or any parent")]
15    JournalNotFound,
16
17    #[error("no entry found with id prefix `{0}`")]
18    EntryNotFound(String),
19
20    #[error("id prefix `{0}` is ambiguous ({1} matches)")]
21    AmbiguousId(String, usize),
22
23    #[error("no entry found with title `{0}`")]
24    EntryNotFoundByTitle(String),
25
26    #[error("title `{0}` is ambiguous ({1} matches)")]
27    AmbiguousTitle(String, usize),
28
29    #[error("duplicate title `{0}` — set duplicate_title = \"allow\" in config to permit this")]
30    DuplicateTitle(String),
31
32    #[error("duplicate id `{0}` found in files: {1} and {2}")]
33    DuplicateId(String, String, String),
34
35    #[error("{0} already exists")]
36    EntryAlreadyExists(String),
37
38    #[error("invalid config: {0}")]
39    InvalidConfig(String),
40
41    #[error("cache error: {0}")]
42    Cache(#[from] rusqlite::Error),
43
44    #[error("embedding error: {0}")]
45    Embed(String),
46
47    /// The cache DB was created by a newer version of archelon.
48    /// The user must either update archelon or recreate the cache.
49    #[error(
50        "cache schema v{db_version} is newer than this app supports (v{app_version}); \
51         update archelon, or recreate the cache with `archelon cache rebuild`"
52    )]
53    CacheSchemaTooNew { db_version: i32, app_version: i32 },
54}
55
56pub type Result<T> = std::result::Result<T, Error>;