lore_engine/engine/
error.rs1use std::fmt;
2use std::sync::PoisonError;
3
4#[derive(Debug)]
6pub enum LoreError {
7 Db(rusqlite::Error),
9 Io(std::io::Error),
11 Lock(String),
13 WatcherError(String),
15 InvalidSlug(String),
17 PageNotFound(String),
19 PlaceholderPage(String),
21 VaultNotSet,
23 UnsafePath(String),
25}
26
27impl fmt::Display for LoreError {
28 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
29 match self {
30 Self::Db(e) => write!(f, "Database error: {e}"),
31 Self::Io(e) => write!(f, "IO error: {e}"),
32 Self::Lock(e) => write!(f, "Lock poisoned: {e}"),
33 Self::WatcherError(e) => write!(f, "File watcher error: {e}"),
34 Self::InvalidSlug(s) => write!(f, "Invalid slug: {s}"),
35 Self::PageNotFound(s) => write!(f, "Page not found: {s}"),
36 Self::PlaceholderPage(s) => write!(f, "Cannot save a placeholder page: {s}"),
37 Self::VaultNotSet => write!(f, "No vault folder selected"),
38 Self::UnsafePath(s) => write!(f, "Unsafe path component: {s}"),
39 }
40 }
41}
42
43impl std::error::Error for LoreError {}
44
45impl From<rusqlite::Error> for LoreError {
46 fn from(e: rusqlite::Error) -> Self {
47 Self::Db(e)
48 }
49}
50
51impl From<std::io::Error> for LoreError {
52 fn from(e: std::io::Error) -> Self {
53 Self::Io(e)
54 }
55}
56
57impl<T> From<PoisonError<T>> for LoreError {
58 fn from(e: PoisonError<T>) -> Self {
59 Self::Lock(e.to_string())
60 }
61}
62
63impl From<LoreError> for String {
64 fn from(e: LoreError) -> Self {
65 e.to_string()
66 }
67}