1use std::path::PathBuf;
2
3#[derive(Debug, thiserror::Error)]
4pub enum VaultError {
5 #[error("'{0}' is not a directory")]
6 NotADirectory(PathBuf),
7 #[error("note already exists at '{0}'")]
8 NoteAlreadyExists(PathBuf),
9 #[error("note not found: '{0}'")]
10 NoteNotFound(String),
11 #[error("ambigous note identifier '{0}'; multiple matches found")]
12 AmbiguousNoteIdentifier(String, Vec<PathBuf>),
13 #[error("directory not found: {0}")]
14 DirectoryNotFound(PathBuf),
15 #[error("source note is the same as destination: '{0}'")]
16 MergeSourceIsDestination(PathBuf),
17 #[error("old-string not found in '{0}'")]
18 StringNotFound(PathBuf),
19 #[error("old-string found multiple times in '{0}'; must match exactly once")]
20 StringFoundMultipleTimes(PathBuf),
21 #[error("invalid extract span in '{path}': {message}")]
22 InvalidExtractSpan { path: PathBuf, message: String },
23 #[error("section '{section}' not found in '{path}'")]
24 SectionNotFound { path: PathBuf, section: String },
25 #[error("section '{section}' is ambiguous in '{path}'")]
26 AmbiguousSection { path: PathBuf, section: String },
27 #[error(transparent)]
28 Io(#[from] std::io::Error),
29 #[error(transparent)]
30 Note(#[from] NoteError),
31 #[error(transparent)]
32 Search(#[from] SearchError),
33}
34
35#[derive(Debug, thiserror::Error)]
36pub enum NoteError {
37 #[error(transparent)]
38 Io(#[from] std::io::Error),
39 #[error("failed to serialize frontmatter: {0}")]
40 Yaml(#[from] serde_yaml::Error),
41 #[error("failed to serialize frontmatter: {0}")]
42 Json(String),
43 #[error("note body not loaded; use from_path() or load_body()")]
44 BodyNotLoaded,
45 #[error("'{0}' is not a valid note path")]
46 InvalidPath(PathBuf),
47 #[error("{0}")]
48 InvalidFieldName(String),
49}
50
51#[derive(Debug, thiserror::Error)]
52pub enum SearchError {
53 #[error("invalid glob pattern: '{0}'")]
54 InvalidGlob(#[from] globset::Error),
55 #[error("invalid regex pattern: '{0}'")]
56 InvalidRegex(#[from] regex::Error),
57}