From 7ac07a7d70fb020b69c4c4ba3c865c93e796df8d Mon Sep 17 00:00:00 2001 From: Noritada Kobayashi Date: Fri, 23 Dec 2022 01:50:55 +0900 Subject: [PATCH] cli: update dependencies on the AWS SDK Since several breaking changes have been made to errors in this update, I have used the following upgrade guide as a reference: https://github.com/awslabs/aws-sdk-rust/issues/657 . --- cli/Cargo.toml | 4 ++-- cli/src/diagnostics.rs | 38 +++++++++++++++++++++++++++----------- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 6e7b8e2..25a259d 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -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" diff --git a/cli/src/diagnostics.rs b/cli/src/diagnostics.rs index 418e56a..1a0e53f 100644 --- a/cli/src/diagnostics.rs +++ b/cli/src/diagnostics.rs @@ -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}; @@ -68,15 +71,28 @@ impl<'e, 'i> std::fmt::Display for SchemaParseErrorReport<'e, 'i> { } } -pub(crate) fn create_s3_download_error_report( - err: SdkError, -) -> 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) -> 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(); @@ -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) }