Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(*): tiny refactor to the Error type #4737

Merged
merged 4 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions core/src/layers/complete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl<A: Access> CompleteAccessor<A> {
let op = op.into();
Error::new(
ErrorKind::Unsupported,
&format!("service {scheme} doesn't support operation {op}"),
format!("service {scheme} doesn't support operation {op}"),
)
.with_operation(op)
}
Expand Down Expand Up @@ -415,7 +415,7 @@ impl<A: Access> LayeredAccess for CompleteAccessor<A> {
if args.append() && !capability.write_can_append {
return Err(Error::new(
ErrorKind::Unsupported,
&format!(
format!(
"service {} doesn't support operation write with append",
self.info().scheme()
),
Expand Down Expand Up @@ -540,7 +540,7 @@ impl<A: Access> LayeredAccess for CompleteAccessor<A> {
if args.append() && !capability.write_can_append {
return Err(Error::new(
ErrorKind::Unsupported,
&format!(
format!(
"service {} doesn't support operation write with append",
self.info().scheme()
),
Expand Down
4 changes: 2 additions & 2 deletions core/src/raw/http_util/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ impl HttpBody {
Ordering::Equal => Ok(()),
Ordering::Less => Err(Error::new(
ErrorKind::Unexpected,
&format!("http response got too little data, expect: {expect}, actual: {actual}"),
format!("http response got too little data, expect: {expect}, actual: {actual}"),
)
.set_temporary()),
Ordering::Greater => Err(Error::new(
ErrorKind::Unexpected,
&format!("http response got too much data, expect: {expect}, actual: {actual}"),
format!("http response got too much data, expect: {expect}, actual: {actual}"),
)
.set_temporary()),
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/raw/std_io_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub fn new_std_io_error(err: std::io::Error) -> Error {
_ => (ErrorKind::Unexpected, true),
};

let mut err = Error::new(kind, &err.kind().to_string()).set_source(err);
let mut err = Error::new(kind, err.kind().to_string()).set_source(err);

if retryable {
err = err.set_temporary();
Expand Down
2 changes: 1 addition & 1 deletion core/src/services/aliyun_drive/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub async fn parse_error(res: Response<Buffer>) -> Result<Error> {
},
_ => (ErrorKind::Unexpected, false),
};
let mut err = Error::new(kind, &message);
let mut err = Error::new(kind, message);
if retryable {
err = err.set_temporary();
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/services/alluxio/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub async fn parse_error(resp: Response<Buffer>) -> Result<Error> {
}
}

let mut err = Error::new(kind, &message);
let mut err = Error::new(kind, message);

err = with_error_response_context(err, parts);

Expand Down
2 changes: 1 addition & 1 deletion core/src/services/azblob/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ impl Access for AzblobBackend {
.map_err(|e| {
Error::new(
ErrorKind::Unexpected,
&format!("get invalid CONTENT_TYPE header in response: {:?}", e),
format!("get invalid CONTENT_TYPE header in response: {:?}", e),
)
})?;
let splits = content_type.split("boundary=").collect::<Vec<&str>>();
Expand Down
2 changes: 1 addition & 1 deletion core/src/services/b2/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub async fn parse_error(resp: Response<Buffer>) -> Result<Error> {
(kind, retryable) = parse_b2_error_code(b2_err.code.as_str()).unwrap_or((kind, retryable));
};

let mut err = Error::new(kind, &message);
let mut err = Error::new(kind, message);

err = with_error_response_context(err, parts);

Expand Down
2 changes: 1 addition & 1 deletion core/src/services/chainsafe/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub async fn parse_error(resp: Response<Buffer>) -> Result<Error> {
.map(|chainsafe_err| (format!("{chainsafe_err:?}"), Some(chainsafe_err)))
.unwrap_or_else(|_| (String::from_utf8_lossy(&bs).into_owned(), None));

let mut err = Error::new(kind, &message);
let mut err = Error::new(kind, message);

err = with_error_response_context(err, parts);

Expand Down
2 changes: 1 addition & 1 deletion core/src/services/cloudflare_kv/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ impl kv::Adapter for Adapter {
serde_json::from_reader(body.reader()).map_err(|e| {
Error::new(
ErrorKind::Unexpected,
&format!("failed to parse error response: {}", e),
format!("failed to parse error response: {}", e),
)
})?;
Ok(response.result.into_iter().map(|r| r.name).collect())
Expand Down
2 changes: 1 addition & 1 deletion core/src/services/cloudflare_kv/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub(crate) async fn parse_error(resp: Response<Buffer>) -> Result<Error> {
(kind, retryable) = parse_cfkv_error_code(err.errors).unwrap_or((kind, retryable));
}

let mut err = Error::new(kind, &message);
let mut err = Error::new(kind, message);

err = with_error_response_context(err, parts);

Expand Down
2 changes: 1 addition & 1 deletion core/src/services/cos/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub async fn parse_error(resp: Response<Buffer>) -> Result<Error> {
Err(_) => String::from_utf8_lossy(&bs).into_owned(),
};

let mut err = Error::new(kind, &message);
let mut err = Error::new(kind, message);

err = with_error_response_context(err, parts);

Expand Down
2 changes: 1 addition & 1 deletion core/src/services/d1/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub async fn parse_error(resp: Response<Buffer>) -> Result<Error> {
(kind, retryable) = parse_d1_error_code(d1_err.errors).unwrap_or((kind, retryable));
}

let mut err = Error::new(kind, &message);
let mut err = Error::new(kind, message);

err = with_error_response_context(err, parts);

Expand Down
4 changes: 2 additions & 2 deletions core/src/services/d1/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ impl D1Response {
let response: D1Response = serde_json::from_slice(bs).map_err(|e| {
Error::new(
crate::ErrorKind::Unexpected,
&format!("failed to parse error response: {}", e),
format!("failed to parse error response: {}", e),
)
})?;

if !response.success {
return Err(Error::new(
crate::ErrorKind::Unexpected,
&String::from_utf8_lossy(bs),
String::from_utf8_lossy(bs),
));
}
Ok(response)
Expand Down
2 changes: 1 addition & 1 deletion core/src/services/dbfs/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub async fn parse_error(resp: Response<Buffer>) -> Result<Error> {
Err(_) => String::from_utf8_lossy(&bs).into_owned(),
};

let mut err = Error::new(kind, &message);
let mut err = Error::new(kind, message);

err = with_error_response_context(err, parts);

Expand Down
6 changes: 3 additions & 3 deletions core/src/services/dropbox/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl Access for DropboxBackend {
if "file" == decoded_response.tag {
return Err(Error::new(
ErrorKind::NotADirectory,
&format!("it's not a directory {}", path),
format!("it's not a directory {}", path),
));
}
}
Expand Down Expand Up @@ -132,7 +132,7 @@ impl Access for DropboxBackend {
} else {
return Err(Error::new(
ErrorKind::Unexpected,
&format!("no size found for file {}", path),
format!("no size found for file {}", path),
));
}
}
Expand Down Expand Up @@ -272,7 +272,7 @@ impl Access for DropboxBackend {
}
_ => Err(Error::new(
ErrorKind::Unexpected,
&format!(
format!(
"delete batch failed with unexpected tag {}",
decoded_response.tag
),
Expand Down
2 changes: 1 addition & 1 deletion core/src/services/dropbox/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ impl DropboxCore {
}
_ => Err(Error::new(
ErrorKind::Unexpected,
&format!(
format!(
"delete batch check failed with unexpected tag {}",
decoded_response.tag
),
Expand Down
2 changes: 1 addition & 1 deletion core/src/services/dropbox/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub async fn parse_error(resp: Response<Buffer>) -> Result<Error> {
parse_dropbox_error_summary(&dropbox_err.error_summary).unwrap_or((kind, retryable));
}

let mut err = Error::new(kind, &message);
let mut err = Error::new(kind, message);

err = with_error_response_context(err, parts);

Expand Down
2 changes: 1 addition & 1 deletion core/src/services/gcs/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub async fn parse_error(resp: Response<Buffer>) -> Result<Error> {
Err(_) => String::from_utf8_lossy(&bs).into_owned(),
};

let mut err = Error::new(kind, &message);
let mut err = Error::new(kind, message);

err = with_error_response_context(err, parts);

Expand Down
6 changes: 3 additions & 3 deletions core/src/services/gdrive/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl GdriveCore {
let path = build_abs_path(&self.root, path);
let file_id = self.path_cache.get(&path).await?.ok_or(Error::new(
ErrorKind::NotFound,
&format!("path not found: {}", path),
format!("path not found: {}", path),
))?;

// The file metadata in the Google Drive API is very complex.
Expand All @@ -80,7 +80,7 @@ impl GdriveCore {
let path = build_abs_path(&self.root, path);
let path_id = self.path_cache.get(&path).await?.ok_or(Error::new(
ErrorKind::NotFound,
&format!("path not found: {}", path),
format!("path not found: {}", path),
))?;

let url: String = format!(
Expand Down Expand Up @@ -129,7 +129,7 @@ impl GdriveCore {
) -> Result<Response<Buffer>> {
let source_file_id = self.path_cache.get(source).await?.ok_or(Error::new(
ErrorKind::NotFound,
&format!("source path not found: {}", source),
format!("source path not found: {}", source),
))?;
let source_parent = get_parent(source);
let source_parent_id = self
Expand Down
2 changes: 1 addition & 1 deletion core/src/services/gdrive/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub async fn parse_error(resp: Response<Buffer>) -> Result<Error> {
parse_gdrive_error_code(gdrive_err.error.message.as_str()).unwrap_or((kind, retryable));
}

let mut err = Error::new(kind, &message);
let mut err = Error::new(kind, message);

err = with_error_response_context(err, parts);

Expand Down
2 changes: 1 addition & 1 deletion core/src/services/ghac/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fn value_or_env(
"{} not found, maybe not in github action environment?",
env_var_name
);
Error::new(ErrorKind::ConfigInvalid, &text)
Error::new(ErrorKind::ConfigInvalid, text)
.with_operation(operation)
.set_source(err)
})
Expand Down
2 changes: 1 addition & 1 deletion core/src/services/ghac/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub async fn parse_error(resp: Response<Buffer>) -> Result<Error> {
let bs = body.copy_to_bytes(body.remaining());
let message = String::from_utf8_lossy(&bs);

let mut err = Error::new(kind, &message);
let mut err = Error::new(kind, message);

err = with_error_response_context(err, parts);

Expand Down
2 changes: 1 addition & 1 deletion core/src/services/github/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub async fn parse_error(resp: Response<Buffer>) -> Result<Error> {
.map(|github_content_err| (format!("{github_content_err:?}"), Some(github_content_err)))
.unwrap_or_else(|_| (String::from_utf8_lossy(&bs).into_owned(), None));

let mut err = Error::new(kind, &message);
let mut err = Error::new(kind, message);

err = with_error_response_context(err, parts);

Expand Down
2 changes: 1 addition & 1 deletion core/src/services/hdfs_native/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub fn parse_hdfs_error(hdfs_error: HdfsError) -> Error {
),
};

let mut err = Error::new(kind, &msg).set_source(hdfs_error);
let mut err = Error::new(kind, msg).set_source(hdfs_error);

if retryable {
err = err.set_temporary();
Expand Down
2 changes: 1 addition & 1 deletion core/src/services/http/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub async fn parse_error(resp: Response<Buffer>) -> Result<Error> {

let message = String::from_utf8_lossy(&bs);

let mut err = Error::new(kind, &message);
let mut err = Error::new(kind, message);

err = with_error_response_context(err, parts);

Expand Down
2 changes: 1 addition & 1 deletion core/src/services/huggingface/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub async fn parse_error(resp: Response<Buffer>) -> Result<Error> {
Err(_) => String::from_utf8_lossy(&bs).into_owned(),
};

let mut err = Error::new(kind, &message);
let mut err = Error::new(kind, message);

err = with_error_response_context(err, parts);

Expand Down
8 changes: 4 additions & 4 deletions core/src/services/icloud/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ impl IcloudCore {

let path_id = self.path_cache.get(base).await?.ok_or(Error::new(
ErrorKind::NotFound,
&format!("read path not found: {}", base),
format!("read path not found: {}", base),
))?;

if let Some(docwsid) = path_id.strip_prefix("FILE::com.apple.CloudDocs::") {
Expand All @@ -456,12 +456,12 @@ impl IcloudCore {

let file_id = self.path_cache.get(base).await?.ok_or(Error::new(
ErrorKind::NotFound,
&format!("stat path not found: {}", base),
format!("stat path not found: {}", base),
))?;

let folder_id = self.path_cache.get(parent).await?.ok_or(Error::new(
ErrorKind::NotFound,
&format!("stat path not found: {}", parent),
format!("stat path not found: {}", parent),
))?;

let node = self.get_root(&folder_id).await?;
Expand Down Expand Up @@ -590,7 +590,7 @@ pub async fn parse_error(resp: Response<Buffer>) -> Result<Error> {
}
}

let mut err = Error::new(kind, &message);
let mut err = Error::new(kind, message);

err = with_error_response_context(err, parts);

Expand Down
2 changes: 1 addition & 1 deletion core/src/services/ipfs/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub async fn parse_error(resp: Response<Buffer>) -> Result<Error> {

let message = String::from_utf8_lossy(&bs);

let mut err = Error::new(kind, &message);
let mut err = Error::new(kind, message);

err = with_error_response_context(err, parts);

Expand Down
2 changes: 1 addition & 1 deletion core/src/services/ipmfs/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub async fn parse_error(resp: Response<Buffer>) -> Result<Error> {
None => String::from_utf8_lossy(&bs).into_owned(),
};

let mut err = Error::new(kind, &message);
let mut err = Error::new(kind, message);

err = with_error_response_context(err, parts);

Expand Down
2 changes: 1 addition & 1 deletion core/src/services/koofr/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub async fn parse_error(resp: Response<Buffer>) -> Result<Error> {

let message = String::from_utf8_lossy(&bs).into_owned();

let mut err = Error::new(kind, &message);
let mut err = Error::new(kind, message);

err = with_error_response_context(err, parts);

Expand Down
2 changes: 1 addition & 1 deletion core/src/services/obs/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub async fn parse_error(resp: Response<Buffer>) -> Result<Error> {
Err(_) => String::from_utf8_lossy(&bs).into_owned(),
};

let mut err = Error::new(kind, &message);
let mut err = Error::new(kind, message);

err = with_error_response_context(err, parts);

Expand Down
2 changes: 1 addition & 1 deletion core/src/services/onedrive/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub async fn parse_error(resp: Response<Buffer>) -> Result<Error> {

let message = String::from_utf8_lossy(&bs);

let mut err = Error::new(kind, &message);
let mut err = Error::new(kind, message);

err = with_error_response_context(err, parts);

Expand Down
2 changes: 1 addition & 1 deletion core/src/services/oss/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub async fn parse_error(resp: Response<Buffer>) -> Result<Error> {
Err(_) => String::from_utf8_lossy(&bs).into_owned(),
};

let mut err = Error::new(kind, &message);
let mut err = Error::new(kind, message);

err = with_error_response_context(err, parts);

Expand Down
Loading
Loading