-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(fuzzy): add error type using thiserror crate
IMHO extracting error messages makes the code more readable This also decouples everything but lib.rs and the lua type wrappers from mlua
- Loading branch information
1 parent
0aaae60
commit 3fa7da1
Showing
5 changed files
with
103 additions
and
94 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#[derive(thiserror::Error, Debug)] | ||
#[non_exhaustive] | ||
pub enum Error { | ||
#[error("Failed to acquire lock for frecency")] | ||
AcquireFrecencyLock, | ||
|
||
#[error("Failed to acquire lock for items by provider")] | ||
AcquireItemLock, | ||
|
||
#[error("Attempted to use frencecy before initialization")] | ||
UseFrecencyBeforeInit, | ||
|
||
#[error( | ||
"Attempted to fuzzy match for provider {provider_id} before setting the provider's items" | ||
)] | ||
FuzzyBeforeSetItems { provider_id: String }, | ||
|
||
#[error("Failed to create frecency database directory: {0}")] | ||
CreateDir(#[source] std::io::Error), | ||
#[error("Failed to open frecency database env: {0}")] | ||
EnvOpen(#[source] heed::Error), | ||
#[error("Failed to create frecency database: {0}")] | ||
DbCreate(#[source] heed::Error), | ||
#[error("Failed to clear stale readers for frecency database: {0}")] | ||
DbClearStaleReaders(#[source] heed::Error), | ||
|
||
#[error("Failed to start read transaction for frecency database: {0}")] | ||
DbStartReadTxn(#[source] heed::Error), | ||
#[error("Failed to start write transaction for frecency database: {0}")] | ||
DbStartWriteTxn(#[source] heed::Error), | ||
|
||
#[error("Failed to read from frecency database: {0}")] | ||
DbRead(#[source] heed::Error), | ||
#[error("Failed to write to frecency database: {0}")] | ||
DbWrite(#[source] heed::Error), | ||
#[error("Failed to commit write transaction to frecency database: {0}")] | ||
DbCommit(#[source] heed::Error), | ||
} | ||
|
||
impl From<Error> for mlua::Error { | ||
fn from(value: Error) -> Self { | ||
mlua::Error::RuntimeError(value.to_string()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters