-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use thiserror crate to implement custom errors (#67)
* refactor: use thiserror crate to implement custom errors * build: track cargo.lock * build: update tantivy * style: run fmt * Revert "build: track cargo.lock" This reverts commit 34c1a5b. * Revert "build: update tantivy" This reverts commit c672c0a.
- Loading branch information
1 parent
43a81c6
commit c8d84a9
Showing
8 changed files
with
58 additions
and
85 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -17,3 +17,4 @@ shellexpand = "3.1.0" | |
uuid = "1.3.2" | ||
colored = "2" | ||
open = "4.1.0" | ||
thiserror = "1.0" |
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 |
---|---|---|
@@ -1,35 +1,27 @@ | ||
use std::fmt; | ||
use std::fmt::Formatter; | ||
use thiserror::Error; | ||
|
||
pub mod index; | ||
|
||
#[derive(Debug)] | ||
#[derive(Debug, Error)] | ||
pub enum LittIndexError { | ||
#[error("Index Creation Error: `{0}`")] | ||
CreationError(String), | ||
#[error("Error updating the index: `{0}`")] | ||
UpdateError(String), | ||
#[error("Error opening existing index: `{0}`")] | ||
OpenError(String), | ||
#[error("Error reloading index writer: `{0}`")] | ||
ReloadError(String), | ||
#[error("Index Write Error: `{0}`")] | ||
WriteError(String), | ||
#[error("Index is not in assumed state: `{0}`")] | ||
StateError(String), | ||
#[error("Index Read Error: `{0}`")] | ||
ReadError(String), | ||
#[error("Error parsing PDF: `{0}`")] | ||
PdfParseError(String), | ||
#[error("Error parsing txt-file: `{0}`")] | ||
TxtParseError(String), | ||
} | ||
|
||
impl fmt::Display for LittIndexError { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { | ||
match &self { | ||
LittIndexError::CreationError(s) => write!(f, "Index Creation Error: {}", s), | ||
LittIndexError::OpenError(s) => write!(f, "Error opening existing index: {}", s), | ||
LittIndexError::UpdateError(s) => write!(f, "Error updating the index: {}", s), | ||
LittIndexError::WriteError(s) => write!(f, "Index Write Error: {}", s), | ||
LittIndexError::ReadError(s) => write!(f, "Index Read Error: {}", s), | ||
LittIndexError::StateError(s) => write!(f, "Index is not in assumed state: {}", s), | ||
LittIndexError::PdfParseError(s) => write!(f, "Error parsing PDF: {}", s), | ||
LittIndexError::TxtParseError(s) => write!(f, "Error parsing txt-file: {}", s), | ||
LittIndexError::ReloadError(s) => write!(f, "Error reloading index writer: {}", s), | ||
} | ||
} | ||
} | ||
|
||
pub type Result<T> = std::result::Result<T, LittIndexError>; |
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
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
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 |
---|---|---|
@@ -1,21 +1,13 @@ | ||
use std::fmt; | ||
use std::fmt::Formatter; | ||
use thiserror::Error; | ||
|
||
pub mod search; | ||
|
||
#[derive(Debug)] | ||
#[derive(Debug, Error)] | ||
pub enum LittSearchError { | ||
#[error("Error initializing new search: `{0}`")] | ||
InitError(String), | ||
#[error("Error during search: `{0}`")] | ||
SearchError(String), | ||
} | ||
|
||
impl fmt::Display for LittSearchError { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { | ||
match &self { | ||
LittSearchError::InitError(s) => write!(f, "Error initializing new search: {}", s), | ||
LittSearchError::SearchError(s) => write!(f, "Error during search: {}", s), | ||
} | ||
} | ||
} | ||
|
||
pub type Result<T> = std::result::Result<T, LittSearchError>; |