diff --git a/aws/rust-runtime/aws-config/src/imds/credentials.rs b/aws/rust-runtime/aws-config/src/imds/credentials.rs index b9a1e053a12..3100fca568f 100644 --- a/aws/rust-runtime/aws-config/src/imds/credentials.rs +++ b/aws/rust-runtime/aws-config/src/imds/credentials.rs @@ -13,11 +13,29 @@ use crate::imds::client::{ImdsError, LazyClient}; use crate::json_credentials::{parse_json_credentials, JsonCredentials, RefreshableCredentials}; use crate::provider_config::ProviderConfig; use aws_smithy_client::SdkError; -use aws_smithy_types::error::display::DisplayErrorContext; use aws_types::credentials::{future, CredentialsError, ProvideCredentials}; use aws_types::os_shim_internal::Env; use aws_types::{credentials, Credentials}; use std::borrow::Cow; +use std::error::Error as StdError; +use std::fmt; + +#[derive(Debug)] +struct ImdsCommunicationError { + source: Box, +} + +impl fmt::Display for ImdsCommunicationError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "could not communicate with IMDS") + } +} + +impl StdError for ImdsCommunicationError { + fn source(&self) -> Option<&(dyn StdError + 'static)> { + Some(self.source.as_ref()) + } +} /// IMDSv2 Credentials Provider /// @@ -138,11 +156,10 @@ impl ImdsCredentialsProvider { ); Err(CredentialsError::not_loaded("received 404 from IMDS")) } - Err(ImdsError::FailedToLoadToken(ref err @ SdkError::DispatchFailure(_))) => { - Err(CredentialsError::not_loaded(format!( - "could not communicate with IMDS: {}", - DisplayErrorContext(&err) - ))) + Err(ImdsError::FailedToLoadToken(err @ SdkError::DispatchFailure(_))) => { + Err(CredentialsError::not_loaded(ImdsCommunicationError { + source: err.into(), + })) } Err(other) => Err(CredentialsError::provider_error(other)), } diff --git a/aws/rust-runtime/aws-sig-auth/src/middleware.rs b/aws/rust-runtime/aws-sig-auth/src/middleware.rs index 1c8770df85a..135b96df20f 100644 --- a/aws/rust-runtime/aws-sig-auth/src/middleware.rs +++ b/aws/rust-runtime/aws-sig-auth/src/middleware.rs @@ -97,9 +97,13 @@ impl Display for SigningStageError { impl Error for SigningStageError { fn source(&self) -> Option<&(dyn Error + 'static)> { + use SigningStageErrorKind as ErrorKind; match &self.kind { - SigningStageErrorKind::SigningFailure(err) => Some(err), - _ => None, + ErrorKind::SigningFailure(err) => Some(err), + ErrorKind::MissingCredentials + | ErrorKind::MissingSigningRegion + | ErrorKind::MissingSigningService + | ErrorKind::MissingSigningConfig => None, } } }