fix: 去除anyhow提供的错误处理,统一使用自定义的Error和Result

This commit is contained in:
shiro.lee
2024-08-05 18:48:45 +08:00
parent a5f9b392ed
commit 7b8c11ecf3
18 changed files with 217 additions and 241 deletions
+2 -4
View File
@@ -1,8 +1,8 @@
mod config;
mod storage;
use anyhow::Result;
use clap::Parser;
use ecstore::error::Result;
use hyper_util::{
rt::{TokioExecutor, TokioIo},
server::conn::auto::Builder as ConnBuilder,
@@ -38,9 +38,7 @@ async fn run(opt: config::Opt) -> Result<()> {
debug!("opt: {:?}", &opt);
// Setup S3 service
let service = {
let mut b = S3ServiceBuilder::new(
storage::ecfs::FS::new(opt.address.clone(), opt.volumes.clone()).await?,
);
let mut b = S3ServiceBuilder::new(storage::ecfs::FS::new(opt.address.clone(), opt.volumes.clone()).await?);
// Enable authentication
if let (Some(ak), Some(sk)) = (opt.access_key, opt.secret_key) {
+4 -4
View File
@@ -1,5 +1,5 @@
use bytes::Bytes;
use ecstore::disk_api::DiskError;
use ecstore::disk::error::DiskError;
use ecstore::store_api::BucketOptions;
use ecstore::store_api::CompletePart;
use ecstore::store_api::HTTPRangeSpec;
@@ -23,7 +23,7 @@ use std::str::FromStr;
use time::OffsetDateTime;
use transform_stream::AsyncTryStream;
use anyhow::Result;
use ecstore::error::Result;
use ecstore::store::ECStore;
use tracing::debug;
@@ -112,7 +112,7 @@ impl S3 for FS {
let input = req.input;
if let Err(e) = self.store.get_bucket_info(&input.bucket, &BucketOptions {}).await {
if DiskError::is_err(&e, &DiskError::VolumeNotFound) {
if DiskError::VolumeNotFound.is(&e) {
return Err(s3_error!(NoSuchBucket));
} else {
return Err(S3Error::with_message(S3ErrorCode::InternalError, format!("{}", e)));
@@ -179,7 +179,7 @@ impl S3 for FS {
let input = req.input;
if let Err(e) = self.store.get_bucket_info(&input.bucket, &BucketOptions {}).await {
if DiskError::is_err(&e, &DiskError::VolumeNotFound) {
if DiskError::VolumeNotFound.is(&e) {
return Err(s3_error!(NoSuchBucket));
} else {
return Err(S3Error::with_message(S3ErrorCode::InternalError, format!("{}", e)));