Skip to content

Commit

Permalink
cli: update dependencies on the AWS SDK
Browse files Browse the repository at this point in the history
Since several breaking changes have been made to errors in this update,
I have used the following upgrade guide as a reference:
awslabs/aws-sdk-rust#657 .
  • Loading branch information
noritada committed Dec 22, 2022
1 parent 99e0da1 commit 7ac07a7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
4 changes: 2 additions & 2 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ path = "src/main.rs"

[dependencies]
anyhow = "1"
aws-config = "0.46"
aws-sdk-s3 = "0.16"
aws-config = "0.52"
aws-sdk-s3 = "0.22"
bytes = "1"
clap = "4"
clap_complete = "4"
Expand Down
38 changes: 27 additions & 11 deletions cli/src/diagnostics.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use anyhow::anyhow;
use aws_sdk_s3::types::SdkError;
use aws_sdk_s3::{
error::{GetObjectError, GetObjectErrorKind},
types::SdkError,
};
use console::Style;
use rrr::{SchemaParseError, SchemaParseErrorKind};

Expand Down Expand Up @@ -68,15 +71,28 @@ impl<'e, 'i> std::fmt::Display for SchemaParseErrorReport<'e, 'i> {
}
}

pub(crate) fn create_s3_download_error_report(
err: SdkError<aws_sdk_s3::error::GetObjectError>,
) -> anyhow::Error {
let reason = match &err {
SdkError::ConstructionFailure(_) => "failed to construct a request before sending",
SdkError::TimeoutError(_) => "request to S3 timed out",
SdkError::DispatchFailure(_) => "request to S3 failed during dispatch",
SdkError::ResponseError { .. } => "received error response",
SdkError::ServiceError { .. } => "error returned from S3",
pub(crate) fn create_s3_download_error_report(err: SdkError<GetObjectError>) -> anyhow::Error {
let body = format!("{err}");
let reason = match err {
SdkError::ConstructionFailure(_) => {
"failed to construct a request before sending".to_owned()
}
SdkError::TimeoutError(_) => "request to S3 timed out".to_owned(),
SdkError::DispatchFailure(_) => "request to S3 failed during dispatch".to_owned(),
e => match e.into_service_error() {
GetObjectError {
kind: GetObjectErrorKind::InvalidObjectState(value),
..
} => format!("invalid object state: {value}"),
GetObjectError {
kind: GetObjectErrorKind::NoSuchKey(_),
..
} => "object does not exist".to_owned(),
err @ GetObjectError { .. } if err.code() == Some("SomeUnmodeledError") => {
"some unhandled error".to_owned()
}
_ => "error returned from S3".to_owned(),
},
};
let yellow_bold = Style::new().yellow().bold();
let bold = Style::new().bold();
Expand All @@ -89,7 +105,7 @@ pub(crate) fn create_s3_download_error_report(
yellow_bold.apply_to("reason"),
bold.apply_to(":"),
bold.apply_to(reason),
err,
body,
);
anyhow!("failed to download an S3 object:\n\n{}", message)
}
Expand Down

0 comments on commit 7ac07a7

Please sign in to comment.