Skip to content

Commit

Permalink
remove unneeded async and result on parse_error
Browse files Browse the repository at this point in the history
improve encapsulation
  • Loading branch information
tsfotis committed Sep 20, 2024
1 parent 362c846 commit 0d55a2d
Show file tree
Hide file tree
Showing 137 changed files with 393 additions and 423 deletions.
2 changes: 1 addition & 1 deletion core/src/services/aliyun_drive/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ impl Access for AliyunDriveBackend {
_ => {
let (part, mut body) = resp.into_parts();
let buf = body.to_buffer().await?;
Err(parse_error(Response::from_parts(part, buf)).await?)
Err(parse_error(Response::from_parts(part, buf)))
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/services/aliyun_drive/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl AliyunDriveCore {
}
let res = self.client.send(req).await?;
if !res.status().is_success() {
return Err(parse_error(res).await?);
return Err(parse_error(res));
}
Ok(res.into_body())
}
Expand Down
6 changes: 3 additions & 3 deletions core/src/services/aliyun_drive/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ use serde::Deserialize;
use crate::*;

#[derive(Default, Debug, Deserialize)]
pub struct AliyunDriveError {
struct AliyunDriveError {
code: String,
message: String,
}

pub async fn parse_error(res: Response<Buffer>) -> Result<Error> {
pub(super) fn parse_error(res: Response<Buffer>) -> Error {
let (parts, mut body) = res.into_parts();
let bs = body.copy_to_bytes(body.remaining());
let (code, message) = serde_json::from_reader::<_, AliyunDriveError>(bs.clone().reader())
Expand All @@ -52,5 +52,5 @@ pub async fn parse_error(res: Response<Buffer>) -> Result<Error> {
if retryable {
err = err.set_temporary();
}
Ok(err)
err
}
2 changes: 1 addition & 1 deletion core/src/services/alluxio/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ impl Access for AlluxioBackend {
if !resp.status().is_success() {
let (part, mut body) = resp.into_parts();
let buf = body.to_buffer().await?;
return Err(parse_error(Response::from_parts(part, buf)).await?);
return Err(parse_error(Response::from_parts(part, buf)));
}
Ok((RpRead::new(), resp.into_body()))
}
Expand Down
18 changes: 9 additions & 9 deletions core/src/services/alluxio/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl AlluxioCore {
let status = resp.status();
match status {
StatusCode::OK => Ok(()),
_ => Err(parse_error(resp).await?),
_ => Err(parse_error(resp)),
}
}

Expand Down Expand Up @@ -160,7 +160,7 @@ impl AlluxioCore {
serde_json::from_reader(body.reader()).map_err(new_json_serialize_error)?;
Ok(steam_id)
}
_ => Err(parse_error(resp).await?),
_ => Err(parse_error(resp)),
}
}

Expand All @@ -184,7 +184,7 @@ impl AlluxioCore {
serde_json::from_reader(body.reader()).map_err(new_json_serialize_error)?;
Ok(steam_id)
}
_ => Err(parse_error(resp).await?),
_ => Err(parse_error(resp)),
}
}

Expand All @@ -204,7 +204,7 @@ impl AlluxioCore {
match status {
StatusCode::OK => Ok(()),
_ => {
let err = parse_error(resp).await?;
let err = parse_error(resp);
if err.kind() == ErrorKind::NotFound {
return Ok(());
}
Expand Down Expand Up @@ -232,7 +232,7 @@ impl AlluxioCore {

match status {
StatusCode::OK => Ok(()),
_ => Err(parse_error(resp).await?),
_ => Err(parse_error(resp)),
}
}

Expand All @@ -258,7 +258,7 @@ impl AlluxioCore {
serde_json::from_reader(body.reader()).map_err(new_json_serialize_error)?;
Ok(file_info)
}
_ => Err(parse_error(resp).await?),
_ => Err(parse_error(resp)),
}
}

Expand All @@ -284,7 +284,7 @@ impl AlluxioCore {
serde_json::from_reader(body.reader()).map_err(new_json_deserialize_error)?;
Ok(file_infos)
}
_ => Err(parse_error(resp).await?),
_ => Err(parse_error(resp)),
}
}

Expand Down Expand Up @@ -320,7 +320,7 @@ impl AlluxioCore {
serde_json::from_reader(body.reader()).map_err(new_json_serialize_error)?;
Ok(size)
}
_ => Err(parse_error(resp).await?),
_ => Err(parse_error(resp)),
}
}

Expand All @@ -337,7 +337,7 @@ impl AlluxioCore {

match status {
StatusCode::OK => Ok(()),
_ => Err(parse_error(resp).await?),
_ => Err(parse_error(resp)),
}
}
}
13 changes: 6 additions & 7 deletions core/src/services/alluxio/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct AlluxioError {
message: String,
}

pub async fn parse_error(resp: Response<Buffer>) -> Result<Error> {
pub(super) fn parse_error(resp: Response<Buffer>) -> Error {
let (parts, mut body) = resp.into_parts();
let bs = body.copy_to_bytes(body.remaining());

Expand All @@ -56,7 +56,7 @@ pub async fn parse_error(resp: Response<Buffer>) -> Result<Error> {

err = with_error_response_context(err, parts);

Ok(err)
err
}

#[cfg(test)]
Expand All @@ -66,8 +66,8 @@ mod tests {
use super::*;

/// Error response example is from https://docs.aws.amazon.com/AmazonS3/latest/API/ErrorResponses.html
#[tokio::test]
async fn test_parse_error() {
#[test]
fn test_parse_error() {
let err_res = vec![
(
r#"{"statusCode":"ALREADY_EXISTS","message":"The resource you requested already exist"}"#,
Expand All @@ -91,10 +91,9 @@ mod tests {
.body(body)
.unwrap();

let err = parse_error(resp).await;
let err = parse_error(resp);

assert!(err.is_ok());
assert_eq!(err.unwrap().kind(), res.1);
assert_eq!(err.kind(), res.1);
}
}
}
12 changes: 6 additions & 6 deletions core/src/services/azblob/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ impl Access for AzblobBackend {

match status {
StatusCode::OK => parse_into_metadata(path, resp.headers()).map(RpStat::new),
_ => Err(parse_error(resp).await?),
_ => Err(parse_error(resp)),
}
}

Expand All @@ -559,7 +559,7 @@ impl Access for AzblobBackend {
_ => {
let (part, mut body) = resp.into_parts();
let buf = body.to_buffer().await?;
Err(parse_error(Response::from_parts(part, buf)).await?)
Err(parse_error(Response::from_parts(part, buf)))
}
}
}
Expand All @@ -586,7 +586,7 @@ impl Access for AzblobBackend {

match status {
StatusCode::ACCEPTED | StatusCode::NOT_FOUND => Ok(RpDelete::default()),
_ => Err(parse_error(resp).await?),
_ => Err(parse_error(resp)),
}
}

Expand All @@ -608,7 +608,7 @@ impl Access for AzblobBackend {

match status {
StatusCode::ACCEPTED => Ok(RpCopy::default()),
_ => Err(parse_error(resp).await?),
_ => Err(parse_error(resp)),
}
}

Expand Down Expand Up @@ -651,7 +651,7 @@ impl Access for AzblobBackend {

// check response status
if resp.status() != StatusCode::ACCEPTED {
return Err(parse_error(resp).await?);
return Err(parse_error(resp));
}

// get boundary from response header
Expand Down Expand Up @@ -701,7 +701,7 @@ impl Access for AzblobBackend {
if resp.status() == StatusCode::ACCEPTED || resp.status() == StatusCode::NOT_FOUND {
results.push((path, Ok(RpDelete::default().into())));
} else {
results.push((path, Err(parse_error(resp).await?)));
results.push((path, Err(parse_error(resp))));
}
}
Ok(RpBatch::new(results))
Expand Down
4 changes: 2 additions & 2 deletions core/src/services/azblob/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl Debug for AzblobError {
}

/// Parse error response into Error.
pub async fn parse_error(resp: Response<Buffer>) -> Result<Error> {
pub(super) fn parse_error(resp: Response<Buffer>) -> Error {
let (parts, mut body) = resp.into_parts();
let bs = body.copy_to_bytes(body.remaining());

Expand Down Expand Up @@ -104,7 +104,7 @@ pub async fn parse_error(resp: Response<Buffer>) -> Result<Error> {
err = err.set_temporary();
}

Ok(err)
err
}

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion core/src/services/azblob/lister.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl oio::PageList for AzblobLister {
.await?;

if resp.status() != http::StatusCode::OK {
return Err(parse_error(resp).await?);
return Err(parse_error(resp));
}

let bs = resp.into_body();
Expand Down
12 changes: 6 additions & 6 deletions core/src/services/azblob/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ impl oio::AppendWrite for AzblobWriter {
// do nothing
}
_ => {
return Err(parse_error(resp).await?);
return Err(parse_error(resp));
}
}
Ok(0)
}
_ => Err(parse_error(resp).await?),
_ => Err(parse_error(resp)),
}
}

Expand All @@ -100,7 +100,7 @@ impl oio::AppendWrite for AzblobWriter {
let status = resp.status();
match status {
StatusCode::CREATED => Ok(()),
_ => Err(parse_error(resp).await?),
_ => Err(parse_error(resp)),
}
}
}
Expand All @@ -118,7 +118,7 @@ impl oio::BlockWrite for AzblobWriter {

match status {
StatusCode::CREATED | StatusCode::OK => Ok(()),
_ => Err(parse_error(resp).await?),
_ => Err(parse_error(resp)),
}
}

Expand All @@ -131,7 +131,7 @@ impl oio::BlockWrite for AzblobWriter {
let status = resp.status();
match status {
StatusCode::CREATED | StatusCode::OK => Ok(()),
_ => Err(parse_error(resp).await?),
_ => Err(parse_error(resp)),
}
}

Expand All @@ -144,7 +144,7 @@ impl oio::BlockWrite for AzblobWriter {
let status = resp.status();
match status {
StatusCode::CREATED | StatusCode::OK => Ok(()),
_ => Err(parse_error(resp).await?),
_ => Err(parse_error(resp)),
}
}

Expand Down
12 changes: 6 additions & 6 deletions core/src/services/azdls/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ impl Access for AzdlsBackend {

match status {
StatusCode::CREATED | StatusCode::OK => Ok(RpCreateDir::default()),
_ => Err(parse_error(resp).await?),
_ => Err(parse_error(resp)),
}
}

Expand All @@ -274,7 +274,7 @@ impl Access for AzdlsBackend {
let resp = self.core.azdls_get_properties(path).await?;

if resp.status() != StatusCode::OK {
return Err(parse_error(resp).await?);
return Err(parse_error(resp));
}

let mut meta = parse_into_metadata(path, resp.headers())?;
Expand Down Expand Up @@ -320,7 +320,7 @@ impl Access for AzdlsBackend {
_ => {
let (part, mut body) = resp.into_parts();
let buf = body.to_buffer().await?;
Err(parse_error(Response::from_parts(part, buf)).await?)
Err(parse_error(Response::from_parts(part, buf)))
}
}
}
Expand All @@ -342,7 +342,7 @@ impl Access for AzdlsBackend {

match status {
StatusCode::OK | StatusCode::NOT_FOUND => Ok(RpDelete::default()),
_ => Err(parse_error(resp).await?),
_ => Err(parse_error(resp)),
}
}

Expand All @@ -357,7 +357,7 @@ impl Access for AzdlsBackend {
let status = resp.status();
match status {
StatusCode::CREATED | StatusCode::CONFLICT => {}
_ => return Err(parse_error(resp).await?),
_ => return Err(parse_error(resp)),
}
}

Expand All @@ -367,7 +367,7 @@ impl Access for AzdlsBackend {

match status {
StatusCode::CREATED => Ok(RpRename::default()),
_ => Err(parse_error(resp).await?),
_ => Err(parse_error(resp)),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/services/azdls/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl Debug for AzdlsError {
}

/// Parse error response into Error.
pub async fn parse_error(resp: Response<Buffer>) -> Result<Error> {
pub(super) fn parse_error(resp: Response<Buffer>) -> Error {
let (parts, mut body) = resp.into_parts();
let bs = body.copy_to_bytes(body.remaining());

Expand Down Expand Up @@ -101,5 +101,5 @@ pub async fn parse_error(resp: Response<Buffer>) -> Result<Error> {
err = err.set_temporary();
}

Ok(err)
err
}
2 changes: 1 addition & 1 deletion core/src/services/azdls/lister.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl oio::PageList for AzdlsLister {
}

if resp.status() != http::StatusCode::OK {
return Err(parse_error(resp).await?);
return Err(parse_error(resp));
}

// Return self at the first page.
Expand Down
Loading

0 comments on commit 0d55a2d

Please sign in to comment.