refact error

Signed-off-by: junxiang Mu <1948535941@qq.com>
This commit is contained in:
junxiang Mu
2024-09-27 16:51:54 +08:00
parent 04ab9d75a9
commit bd02676dbc
21 changed files with 110 additions and 22 deletions
+1 -1
View File
@@ -2,7 +2,7 @@ use rmp_serde::Serializer;
use serde::{Deserialize, Serialize};
use time::OffsetDateTime;
use common::error::Result;
use crate::error::Result;
use crate::disk::BUCKET_META_PREFIX;
+1 -1
View File
@@ -1,5 +1,5 @@
use crate::error::StdError;
use bytes::Bytes;
use common::error::StdError;
use futures::pin_mut;
use futures::stream::{Stream, StreamExt};
use std::future::Future;
+1 -1
View File
@@ -1,5 +1,5 @@
use crate::error::{Error, Result};
use crate::utils::net;
use common::error::{Error, Result};
use path_absolutize::Absolutize;
use path_clean::PathClean;
use std::{fmt::Display, path::Path};
+1 -1
View File
@@ -1,4 +1,4 @@
use common::error::{Error, Result};
use crate::error::{Error, Result};
#[derive(Debug, thiserror::Error)]
pub enum DiskError {
+1 -1
View File
@@ -1,5 +1,5 @@
use super::error::DiskError;
use common::error::{Error, Result};
use crate::error::{Error, Result};
use serde::{Deserialize, Serialize};
use serde_json::Error as JsonError;
use uuid::Uuid;
+1 -1
View File
@@ -4,13 +4,13 @@ use super::{
ReadOptions, RenameDataResp, VolumeInfo, WalkDirOptions,
};
use crate::disk::{LocalFileReader, LocalFileWriter, STORAGE_FORMAT_FILE};
use crate::error::{Error, Result};
use crate::{
file_meta::FileMeta,
store_api::{FileInfo, RawFileInfo},
utils,
};
use bytes::Bytes;
use common::error::{Error, Result};
use path_absolutize::Absolutize;
use std::{
fs::Metadata,
+1 -1
View File
@@ -14,11 +14,11 @@ const STORAGE_FORMAT_FILE: &str = "xl.meta";
use crate::{
erasure::{ReadAt, Write},
error::{Error, Result},
file_meta::FileMeta,
store_api::{FileInfo, RawFileInfo},
};
use bytes::Bytes;
use common::error::{Error, Result};
use futures::StreamExt;
use protos::proto_gen::node_service::{
node_service_client::NodeServiceClient, ReadAtRequest, ReadAtResponse, WriteRequest, WriteResponse,
+1 -1
View File
@@ -1,7 +1,6 @@
use std::path::PathBuf;
use bytes::Bytes;
use common::error::{Error, Result};
use futures::lock::Mutex;
use protos::{
node_service_time_out_client,
@@ -17,6 +16,7 @@ use uuid::Uuid;
use crate::{
disk::error::DiskError,
error::{Error, Result},
store_api::{FileInfo, RawFileInfo},
};
+1 -1
View File
@@ -1,5 +1,5 @@
use crate::error::{Error, Result};
use crate::utils::ellipses::*;
use common::error::{Error, Result};
use serde::Deserialize;
use std::collections::HashSet;
+1 -1
View File
@@ -1,9 +1,9 @@
use crate::{
disk::endpoint::{Endpoint, EndpointType},
disks_layout::DisksLayout,
error::{Error, Result},
utils::net,
};
use common::error::{Error, Result};
use std::{
collections::{hash_map::Entry, HashMap, HashSet},
net::IpAddr,
+1 -1
View File
@@ -1,5 +1,5 @@
use crate::error::{Error, Result, StdError};
use bytes::Bytes;
use common::error::{Error, Result, StdError};
use futures::future::join_all;
use futures::{Stream, StreamExt};
use reed_solomon_erasure::galois_8::ReedSolomon;
+82
View File
@@ -0,0 +1,82 @@
use tracing_error::{SpanTrace, SpanTraceStatus};
pub type StdError = Box<dyn std::error::Error + Send + Sync + 'static>;
pub type Result<T = (), E = Error> = std::result::Result<T, E>;
#[derive(Debug)]
pub struct Error {
inner: Box<dyn std::error::Error + Send + Sync + 'static>,
span_trace: SpanTrace,
}
impl Error {
/// Create a new error from a `std::error::Error`.
#[must_use]
#[track_caller]
pub fn new<T: std::error::Error + Send + Sync + 'static>(source: T) -> Self {
Self::from_std_error(source.into())
}
/// Create a new error from a `std::error::Error`.
#[must_use]
#[track_caller]
pub fn from_std_error(inner: StdError) -> Self {
Self {
inner,
span_trace: SpanTrace::capture(),
}
}
/// Create a new error from a string.
#[must_use]
#[track_caller]
pub fn from_string(s: impl Into<String>) -> Self {
Self::msg(s)
}
/// Create a new error from a string.
#[must_use]
#[track_caller]
pub fn msg(s: impl Into<String>) -> Self {
Self::from_std_error(s.into().into())
}
/// Returns `true` if the inner type is the same as `T`.
#[inline]
pub fn is<T: std::error::Error + 'static>(&self) -> bool {
self.inner.is::<T>()
}
/// Returns some reference to the inner value if it is of type `T`, or
/// `None` if it isn't.
#[inline]
pub fn downcast_ref<T: std::error::Error + 'static>(&self) -> Option<&T> {
self.inner.downcast_ref()
}
/// Returns some mutable reference to the inner value if it is of type `T`, or
/// `None` if it isn't.
#[inline]
pub fn downcast_mut<T: std::error::Error + 'static>(&mut self) -> Option<&mut T> {
self.inner.downcast_mut()
}
}
impl<T: std::error::Error + Send + Sync + 'static> From<T> for Error {
fn from(e: T) -> Self {
Self::new(e)
}
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.inner)?;
if self.span_trace.status() != SpanTraceStatus::EMPTY {
write!(f, "\nspan_trace:\n{}", self.span_trace)?;
}
Ok(())
}
}
+1
View File
@@ -4,6 +4,7 @@ pub mod disk;
pub mod disks_layout;
pub mod endpoints;
pub mod erasure;
pub mod error;
mod file_meta;
pub mod peer;
pub mod set_disk;
+1 -1
View File
@@ -1,5 +1,4 @@
use async_trait::async_trait;
use common::error::{Error, Result};
use futures::future::join_all;
use protos::node_service_time_out_client;
use protos::proto_gen::node_service::{DeleteBucketRequest, GetBucketInfoRequest, ListBucketRequest, MakeBucketRequest};
@@ -12,6 +11,7 @@ use crate::store::all_local_disk;
use crate::{
disk::{self, error::DiskError, VolumeInfo},
endpoints::{EndpointServerPools, Node},
error::{Error, Result},
store_api::{BucketInfo, BucketOptions, MakeBucketOptions},
};
+1 -1
View File
@@ -1,6 +1,5 @@
use std::{collections::HashMap, sync::Arc};
use common::error::{Error, Result};
use common::globals::GLOBAL_Local_Node_Name;
use futures::future::join_all;
use http::HeaderMap;
@@ -14,6 +13,7 @@ use crate::{
DiskStore,
},
endpoints::PoolEndpoints,
error::{Error, Result},
set_disk::SetDisks,
store::{GLOBAL_IsDistErasure, GLOBAL_LOCAL_DISK_SET_DRIVES},
store_api::{
+1 -1
View File
@@ -5,6 +5,7 @@ use crate::{
BUCKET_META_PREFIX, RUSTFS_META_BUCKET,
},
endpoints::{EndpointServerPools, SetupType},
error::{Error, Result},
peer::S3PeerSys,
sets::Sets,
store_api::{
@@ -15,7 +16,6 @@ use crate::{
store_init, utils,
};
use backon::{ExponentialBuilder, Retryable};
use common::error::{Error, Result};
use common::globals::{GLOBAL_Local_Node_Name, GLOBAL_Rustfs_Host, GLOBAL_Rustfs_Port};
use futures::future::join_all;
use http::HeaderMap;
+1 -1
View File
@@ -1,4 +1,4 @@
use common::error::{Error, Result};
use crate::error::{Error, Result};
use http::HeaderMap;
use rmp_serde::Serializer;
use s3s::dto::StreamingBlob;
+1 -1
View File
@@ -5,8 +5,8 @@ use crate::{
new_disk, DiskOption, DiskStore, FORMAT_CONFIG_FILE, RUSTFS_META_BUCKET,
},
endpoints::Endpoints,
error::{Error, Result},
};
use common::error::{Error, Result};
use futures::future::join_all;
use std::{
collections::{hash_map::Entry, HashMap},
+1 -1
View File
@@ -1,4 +1,4 @@
use common::error::{Error, Result};
use crate::error::{Error, Result};
use lazy_static::*;
use regex::Regex;
+1 -1
View File
@@ -1,4 +1,4 @@
use common::error::{Error, Result};
use crate::error::{Error, Result};
use lazy_static::lazy_static;
use std::{
collections::HashSet,