Skip to main content

fff_search/
error.rs

1use std::path::StripPrefixError;
2
3#[derive(thiserror::Error, Debug)]
4#[non_exhaustive]
5pub enum Error {
6    #[error("Thread panicked")]
7    ThreadPanic,
8    #[error("Invalid path {0}")]
9    InvalidPath(std::path::PathBuf),
10    #[error(
11        "Can not run certain FFF features in a file system root or home directories. Consider smaller per-project directories."
12    )]
13    FilesystemRoot(std::path::PathBuf),
14    #[error("File picker not initialized")]
15    FilePickerMissing,
16    #[error("Failed to acquire lock for frecency")]
17    AcquireFrecencyLock,
18    #[error("Failed to acquire lock for items by provider")]
19    AcquireItemLock,
20    #[error("Failed to acquire lock for path cache")]
21    AcquirePathCacheLock,
22    #[error("Failed to create directory: {0}")]
23    CreateDir(#[from] std::io::Error),
24    #[error("Failed to remove database directory {path}: {source}")]
25    RemoveDbDir {
26        path: std::path::PathBuf,
27        source: std::io::Error,
28    },
29    #[error("Something is wrong with the local db instance: {0}")]
30    GenericDbError(#[from] heed::Error),
31    #[error("Failed to open {db} database env: {source}")]
32    EnvOpen {
33        db: &'static str,
34        #[source]
35        source: heed::Error,
36    },
37    #[error(
38        "LMDB env at {path} is already open as the '{open_as}' database with different options; requested by '{requested_as}'. Use a distinct path per database."
39    )]
40    EnvSpecMismatch {
41        path: std::path::PathBuf,
42        open_as: &'static str,
43        requested_as: &'static str,
44    },
45    #[error(
46        "The {db} database at {path} is still used by {holders} other tracker(s) in this process"
47    )]
48    DbInUse {
49        db: &'static str,
50        path: std::path::PathBuf,
51        holders: usize,
52    },
53    #[error("Failed to create {db} database: {source}")]
54    DbCreate {
55        db: &'static str,
56        #[source]
57        source: heed::Error,
58    },
59    #[error("Failed to open {db} database: {source}")]
60    DbOpen {
61        db: &'static str,
62        #[source]
63        source: heed::Error,
64    },
65    #[error("Failed to clear stale readers for {db} database: {source}")]
66    DbClearStaleReaders {
67        db: &'static str,
68        #[source]
69        source: heed::Error,
70    },
71
72    #[error("Failed to start read transaction for {db} database: {source}")]
73    DbStartReadTxn {
74        db: &'static str,
75        #[source]
76        source: heed::Error,
77    },
78    #[error("Failed to start write transaction for {db} database: {source}")]
79    DbStartWriteTxn {
80        db: &'static str,
81        #[source]
82        source: heed::Error,
83    },
84    #[error("Failed to read from {db} database: {source}")]
85    DbRead {
86        db: &'static str,
87        #[source]
88        source: heed::Error,
89    },
90    #[error("Failed to write to {db} database: {source}")]
91    DbWrite {
92        db: &'static str,
93        #[source]
94        source: heed::Error,
95    },
96    #[error("Failed to commit write transaction to {db} database: {source}")]
97    DbCommit {
98        db: &'static str,
99        #[source]
100        source: heed::Error,
101    },
102    #[error("Failed to start file system watcher: {0}")]
103    FileSystemWatch(#[from] notify::Error),
104
105    #[error("Expected a path to be child of another path: {0}")]
106    StripPrefixError(#[from] StripPrefixError),
107
108    #[error("libgit2 error occurred: {0}")]
109    Git(#[from] git2::Error),
110
111    #[error("Filesystem walk failed: {0}")]
112    WalkFailed(String),
113
114    #[error("Invalid glob pattern '{pattern}': {reason}")]
115    InvalidGlobPattern { pattern: String, reason: String },
116
117    #[error("File system watching is disabled for this picker")]
118    WatcherDisabled,
119
120    #[error("File system watcher is not ready")]
121    WatcherNotReady,
122
123    #[error("Indexed base path changed while creating the watch subscription")]
124    WatchBaseChanged,
125
126    #[error("Failed to start watch callback dispatcher: {0}")]
127    WatchDispatcherStart(#[source] std::io::Error),
128}
129
130pub type Result<T> = std::result::Result<T, Error>;