1use std::io;
8use std::path::PathBuf;
9use thiserror::Error;
10
11pub type Result<T, E = CoreError> = std::result::Result<T, E>;
12
13#[derive(Debug, Error)]
14pub enum CoreError {
15 #[error("io error: {0}")]
16 Io(#[from] io::Error),
17
18 #[error("toml error: {0}")]
19 Toml(#[from] toml::de::Error),
20
21 #[error("toml serialize error: {0}")]
22 TomlSerialize(#[from] toml::ser::Error),
23
24 #[error("redb error: {0}")]
25 Redb(#[from] redb::Error),
26
27 #[error("redb database error: {0}")]
28 RedbDb(#[from] redb::DatabaseError),
29
30 #[error("redb transaction error: {0}")]
31 RedbTx(#[from] redb::TransactionError),
32
33 #[error("redb storage error: {0}")]
34 RedbStorage(#[from] redb::StorageError),
35
36 #[error("redb table error: {0}")]
37 RedbTable(#[from] redb::TableError),
38
39 #[error("redb commit error: {0}")]
40 RedbCommit(#[from] redb::CommitError),
41
42 #[error("tantivy error: {0}")]
43 Tantivy(#[from] tantivy::TantivyError),
44
45 #[error("notify watcher error: {0}")]
46 Notify(#[from] notify::Error),
47
48 #[error("tantivy query parse error: {0}")]
49 QueryParse(#[from] tantivy::query::QueryParserError),
50
51 #[error("json error: {0}")]
52 Json(#[from] serde_json::Error),
53
54 #[error("time parse error: {0}")]
55 TimeParse(#[from] time::error::Parse),
56
57 #[error("time format error: {0}")]
58 TimeFormat(#[from] time::error::Format),
59
60 #[error("uuid error: {0}")]
61 Uuid(#[from] uuid::Error),
62
63 #[error("memo not found: {0}")]
64 NotFound(String),
65
66 #[error("invalid memo id: {0}")]
67 InvalidMemoId(String),
68
69 #[error("corrupt frontmatter in {path}: {reason}")]
72 Frontmatter { path: PathBuf, reason: String },
73
74 #[error("vault is not initialized at {0}")]
75 NotInitialized(PathBuf),
76
77 #[error("index lock held by another process (timed out after {0}s)")]
78 LockTimeout(u64),
79
80 #[error("ids option conflict: only one of --ids/--ids-file/--ids-stdin may be used")]
81 IdsOptionConflict,
82
83 #[error("image rejected: {0}")]
84 AssetRejected(String),
85
86 #[error("{0}")]
87 Other(String),
88}
89
90impl CoreError {
91 pub fn other(msg: impl Into<String>) -> Self {
92 Self::Other(msg.into())
93 }
94}