mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-21 03:46:37 +00:00
refactor error framework
Signed-off-by: junxiang Mu <1948535941@qq.com>
This commit is contained in:
+19
-2
@@ -1,13 +1,13 @@
|
||||
use crate::config::error::ConfigError;
|
||||
use crate::{disk::error::DiskError, error::Error};
|
||||
use std::{collections::HashMap, fmt::Debug};
|
||||
|
||||
// pub type CheckErrorFn = fn(e: &Error) -> bool;
|
||||
|
||||
pub trait CheckErrorFn: Debug + Send + Sync + 'static {
|
||||
fn is(&self, e: &Error) -> bool;
|
||||
}
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
#[derive(Debug, PartialEq, thiserror::Error)]
|
||||
pub enum QuorumError {
|
||||
#[error("Read quorum not met")]
|
||||
Read,
|
||||
@@ -15,6 +15,23 @@ pub enum QuorumError {
|
||||
Write,
|
||||
}
|
||||
|
||||
impl QuorumError {
|
||||
pub fn to_u32(&self) -> u32 {
|
||||
match self {
|
||||
QuorumError::Read => 0x01,
|
||||
QuorumError::Write => 0x02,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_u32(error: u32) -> Option<Self> {
|
||||
match error {
|
||||
0x01 => Some(QuorumError::Read),
|
||||
0x02 => Some(QuorumError::Write),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn base_ignored_errs() -> Vec<Box<dyn CheckErrorFn>> {
|
||||
vec![
|
||||
Box::new(DiskError::DiskNotFound),
|
||||
|
||||
Reference in New Issue
Block a user