-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
25 additions
and
54 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
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,83 +1,55 @@ | ||
use std::fmt::{Debug, Display, Formatter}; | ||
|
||
/// CacheError contains the error of this crate | ||
#[derive(thiserror::Error, Debug)] | ||
pub enum CacheError { | ||
/// Count Min sketch with wrong width. | ||
#[error("invalid number of samples: {0}")] | ||
InvalidCountMinWidth(u64), | ||
|
||
/// Invalid Samples value for TinyLFU. | ||
#[error("invalid count main sketch width: {0}")] | ||
InvalidSamples(usize), | ||
|
||
/// Invalid false positive ratio for TinyLFU. | ||
#[error("invalid false positive ratio: {0}, which should be in range (0.0, 1.0)")] | ||
InvalidFalsePositiveRatio(f64), | ||
|
||
/// Invalid number of counters for the Cache. | ||
#[error("num_counters can't be zero")] | ||
InvalidNumCounters, | ||
|
||
/// Invalid max cost for the Cache. | ||
#[error("max_cost can't be zero")] | ||
InvalidMaxCost, | ||
|
||
/// Invalid insert buffer size for the Cache. | ||
#[error("buffer_size can't be zero")] | ||
InvalidBufferSize, | ||
|
||
/// Error when send msg between threads. | ||
#[error("fail to send msg to channel: {0}")] | ||
SendError(String), | ||
|
||
/// Error when receive msg between threads. | ||
#[error("fail to receive msg from channel: {0}")] | ||
RecvError(String), | ||
|
||
/// Error when updating entries | ||
#[error("update error: {0}")] | ||
UpdateError(String), | ||
|
||
/// Error when inserting entries | ||
#[error("insert error: {0}")] | ||
InsertError(String), | ||
|
||
/// Error when removing entries | ||
#[error("remove error: {0}")] | ||
RemoveError(String), | ||
|
||
/// Error when cleaning up | ||
#[error("cleanup error: {0}")] | ||
CleanupError(String), | ||
|
||
/// Channel send error | ||
#[error("channel error: {0}")] | ||
ChannelError(String), | ||
} | ||
|
||
impl CacheError { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { | ||
match self { | ||
CacheError::InvalidSamples(v) => write!(f, "invalid number of samples: {}", *v), | ||
CacheError::InvalidCountMinWidth(v) => { | ||
write!(f, "invalid count main sketch width: {}", *v) | ||
} | ||
CacheError::InvalidFalsePositiveRatio(v) => write!( | ||
f, | ||
"invalid false positive ratio: {}, which should be in range (0.0, 1.0)", | ||
*v | ||
), | ||
CacheError::SendError(msg) => write!(f, "fail to send msg to channel: {}", msg), | ||
CacheError::RecvError(msg) => write!(f, "fail to receive msg from channel: {}", msg), | ||
CacheError::InvalidNumCounters => write!(f, "num_counters can't be zero"), | ||
CacheError::InvalidMaxCost => write!(f, "max_cost can't be zero"), | ||
CacheError::InvalidBufferSize => write!(f, "buffer_size can't be zero"), | ||
CacheError::UpdateError(msg) => write!(f, "update error: {} ", msg), | ||
CacheError::InsertError(msg) => write!(f, "insert error: {} ", msg), | ||
CacheError::RemoveError(msg) => write!(f, "remove error: {} ", msg), | ||
CacheError::CleanupError(msg) => write!(f, "cleanup error: {} ", msg), | ||
CacheError::ChannelError(msg) => write!(f, "channel error: {} ", msg), | ||
} | ||
} | ||
} | ||
|
||
impl Display for CacheError { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { | ||
self.fmt(f) | ||
} | ||
} | ||
|
||
impl Debug for CacheError { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { | ||
self.fmt(f) | ||
} | ||
} | ||
|
||
impl std::error::Error for CacheError {} |
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