Skip to content

Commit

Permalink
Apply DisplayErrorContext to all tracing statements
Browse files Browse the repository at this point in the history
  • Loading branch information
jdisanti committed Oct 21, 2022
1 parent 8a099b3 commit 308b419
Show file tree
Hide file tree
Showing 16 changed files with 46 additions and 37 deletions.
3 changes: 2 additions & 1 deletion aws/rust-runtime/aws-config/src/ecs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ use std::net::IpAddr;

use aws_smithy_client::erase::boxclone::BoxCloneService;
use aws_smithy_http::endpoint::Endpoint;
use aws_smithy_types::error::display::DisplayErrorContext;
use aws_types::credentials;
use aws_types::credentials::{future, CredentialsError, ProvideCredentials};
use http::uri::{InvalidUri, Scheme};
Expand Down Expand Up @@ -182,7 +183,7 @@ impl Provider {
let mut relative_uri = match relative_uri.parse::<Uri>() {
Ok(uri) => uri,
Err(invalid_uri) => {
tracing::warn!(uri = ?invalid_uri, "invalid URI loaded from environment");
tracing::warn!(uri = %DisplayErrorContext(&invalid_uri), "invalid URI loaded from environment");
return Err(EcsConfigurationErr::InvalidRelativeUri {
err: invalid_uri,
uri: relative_uri,
Expand Down
3 changes: 2 additions & 1 deletion aws/rust-runtime/aws-config/src/environment/app_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

use aws_smithy_types::error::display::DisplayErrorContext;
use aws_types::app_name::AppName;
use aws_types::os_shim_internal::Env;

Expand Down Expand Up @@ -32,7 +33,7 @@ impl EnvironmentVariableAppNameProvider {
match AppName::new(name) {
Ok(name) => Some(name),
Err(err) => {
tracing::warn!(err = %err, "`AWS_SDK_UA_APP_ID` environment variable value was invalid");
tracing::warn!(err = %DisplayErrorContext(&err), "`AWS_SDK_UA_APP_ID` environment variable value was invalid");
None
}
}
Expand Down
3 changes: 2 additions & 1 deletion aws/rust-runtime/aws-config/src/imds/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use aws_smithy_http::retry::ClassifyRetry;
use aws_smithy_http_tower::map_request::{
AsyncMapRequestLayer, AsyncMapRequestService, MapRequestLayer, MapRequestService,
};
use aws_smithy_types::error::display::DisplayErrorContext;
use aws_smithy_types::retry::{ErrorKind, RetryKind};
use aws_types::os_shim_internal::{Env, Fs};

Expand Down Expand Up @@ -163,7 +164,7 @@ impl LazyClient {
.get_or_init(|| async {
let client = builder.clone().build().await;
if let Err(err) = &client {
tracing::warn!(err = % err, "failed to create IMDS client")
tracing::warn!(err = %DisplayErrorContext(err), "failed to create IMDS client")
}
client
})
Expand Down
2 changes: 1 addition & 1 deletion aws/rust-runtime/aws-config/src/imds/credentials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl ImdsCredentialsProvider {
Err(ImdsError::ErrorResponse { response, .. }) if response.status().as_u16() == 404 => {
tracing::info!(
"received 404 from IMDS when loading profile information. \
Hint: This instance may not have an IAM role associated."
Hint: This instance may not have an IAM role associated."
);
Err(CredentialsError::not_loaded("received 404 from IMDS"))
}
Expand Down
7 changes: 3 additions & 4 deletions aws/rust-runtime/aws-config/src/imds/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ use crate::imds;
use crate::imds::client::LazyClient;
use crate::meta::region::{future, ProvideRegion};
use crate::provider_config::ProviderConfig;

use aws_smithy_types::error::display::DisplayErrorContext;
use aws_types::os_shim_internal::Env;
use aws_types::region::Region;

use tracing::Instrument;

/// IMDSv2 Region Provider
Expand Down Expand Up @@ -53,11 +52,11 @@ impl ImdsRegionProvider {
let client = self.client.client().await.ok()?;
match client.get(REGION_PATH).await {
Ok(region) => {
tracing::debug!(region = % region, "loaded region from IMDS");
tracing::debug!(region = %region, "loaded region from IMDS");
Some(Region::new(region))
}
Err(err) => {
tracing::warn!(err = % err, "failed to load region from IMDS");
tracing::warn!(err = %DisplayErrorContext(&err), "failed to load region from IMDS");
None
}
}
Expand Down
6 changes: 3 additions & 3 deletions aws/rust-runtime/aws-config/src/meta/credentials/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* SPDX-License-Identifier: Apache-2.0
*/

use std::borrow::Cow;

use aws_smithy_types::error::display::DisplayErrorContext;
use aws_types::credentials::{self, future, CredentialsError, ProvideCredentials};
use std::borrow::Cow;
use tracing::Instrument;

/// Credentials provider that checks a series of inner providers
Expand Down Expand Up @@ -86,7 +86,7 @@ impl CredentialsProviderChain {
tracing::debug!(provider = %name, context = %context, "provider in chain did not provide credentials");
}
Err(e) => {
tracing::warn!(provider = %name, error = %e, "provider failed to provide credentials");
tracing::warn!(provider = %name, error = %DisplayErrorContext(&e), "provider failed to provide credentials");
return Err(e);
}
}
Expand Down
5 changes: 4 additions & 1 deletion aws/rust-runtime/aws-config/src/profile/app_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use super::profile_file::ProfileFiles;
use crate::provider_config::ProviderConfig;
use aws_smithy_types::error::display::DisplayErrorContext;
use aws_types::app_name::AppName;
use aws_types::os_shim_internal::{Env, Fs};

Expand Down Expand Up @@ -63,7 +64,9 @@ impl ProfileFileAppNameProvider {
pub async fn app_name(&self) -> Option<AppName> {
let profile = super::parser::load(&self.fs, &self.env, &self.profile_files)
.await
.map_err(|err| tracing::warn!(err = %err, "failed to parse profile"))
.map_err(
|err| tracing::warn!(err = %DisplayErrorContext(&err), "failed to parse profile"),
)
.ok()?;
let selected_profile_name = self
.profile_override
Expand Down
3 changes: 2 additions & 1 deletion aws/rust-runtime/aws-config/src/profile/credentials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use crate::profile::parser::ProfileParseError;
use crate::profile::profile_file::ProfileFiles;
use crate::profile::Profile;
use crate::provider_config::ProviderConfig;
use aws_smithy_types::error::display::DisplayErrorContext;
use aws_types::credentials::{self, future, CredentialsError, ProvideCredentials};
use std::borrow::Cow;
use std::collections::HashMap;
Expand Down Expand Up @@ -186,7 +187,7 @@ impl ProfileFileCredentialsProvider {
creds
}
Err(e) => {
tracing::warn!(error = %e, "failed to load base credentials");
tracing::warn!(error = %DisplayErrorContext(&e), "failed to load base credentials");
return Err(CredentialsError::provider_error(e));
}
};
Expand Down
9 changes: 4 additions & 5 deletions aws/rust-runtime/aws-config/src/profile/parser/normalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
* SPDX-License-Identifier: Apache-2.0
*/

use std::borrow::Cow;
use std::collections::HashMap;

use crate::profile::parser::parse::{RawProfileSet, WHITESPACE};
use crate::profile::profile_file::ProfileFileKind;
use crate::profile::{Profile, ProfileSet, Property};
use std::borrow::Cow;
use std::collections::HashMap;

const DEFAULT: &str = "default";
const PROFILE_PREFIX: &str = "profile";
Expand Down Expand Up @@ -84,8 +83,8 @@ pub(super) fn merge_in(
let valid_profiles = validated_profiles
.filter_map(|(name, profile)| match name {
Ok(profile_name) => Some((profile_name, profile)),
Err(e) => {
tracing::warn!("{}", e);
Err(err_str) => {
tracing::warn!("{}", err_str);
None
}
})
Expand Down
5 changes: 3 additions & 2 deletions aws/rust-runtime/aws-config/src/profile/parser/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use crate::fs_util::{home_dir, Os};
use crate::profile::credentials::{CouldNotReadProfileFile, ProfileFileError};
use crate::profile::profile_file::{ProfileFile, ProfileFileKind, ProfileFiles};
use aws_smithy_types::error::display::DisplayErrorContext;
use aws_types::os_shim_internal;
use std::borrow::Cow;
use std::io::ErrorKind;
Expand Down Expand Up @@ -64,7 +65,7 @@ fn file_contents_to_string(path: &Path, contents: Vec<u8>) -> String {
match String::from_utf8(contents) {
Ok(contents) => contents,
Err(e) => {
tracing::warn!(path = ?path, error = %e, "config file did not contain utf-8 encoded data");
tracing::warn!(path = ?path, error = %DisplayErrorContext(&e), "config file did not contain utf-8 encoded data");
Default::default()
}
}
Expand Down Expand Up @@ -113,7 +114,7 @@ async fn load_config_file(
tracing::warn!(path = %path, env = %kind.override_environment_variable(), "config file overridden via environment variable not found")
}
_other => {
tracing::warn!(path = %path, error = %e, "failed to read config file")
tracing::warn!(path = %path, error = %DisplayErrorContext(&e), "failed to read config file")
}
};
Default::default()
Expand Down
10 changes: 6 additions & 4 deletions aws/rust-runtime/aws-config/src/profile/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
//! Load a region from an AWS profile
use crate::meta::region::{future, ProvideRegion};
use crate::profile::profile_file::ProfileFiles;
use crate::profile::ProfileSet;
use crate::provider_config::ProviderConfig;
use aws_smithy_types::error::display::DisplayErrorContext;
use aws_types::os_shim_internal::{Env, Fs};
use aws_types::region::Region;

use super::profile_file::ProfileFiles;
use super::ProfileSet;

/// Load a region from a profile file
///
/// This provider will attempt to load AWS shared configuration, then read the `region` property
Expand Down Expand Up @@ -105,7 +105,9 @@ impl ProfileFileRegionProvider {
async fn region(&self) -> Option<Region> {
let profile_set = super::parser::load(&self.fs, &self.env, &self.profile_files)
.await
.map_err(|err| tracing::warn!(err = %err, "failed to parse profile"))
.map_err(
|err| tracing::warn!(err = %DisplayErrorContext(&err), "failed to parse profile"),
)
.ok()?;

resolve_profile_chain_for_region(&profile_set, self.profile_override.as_deref())
Expand Down
11 changes: 5 additions & 6 deletions aws/rust-runtime/aws-config/src/profile/retry_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@

//! Load retry configuration properties from an AWS profile
use std::str::FromStr;

use crate::profile::profile_file::ProfileFiles;
use crate::provider_config::ProviderConfig;
use aws_smithy_types::error::display::DisplayErrorContext;
use aws_smithy_types::retry::{RetryConfigBuilder, RetryConfigErr, RetryMode};
use aws_types::os_shim_internal::{Env, Fs};

use super::profile_file::ProfileFiles;
use crate::provider_config::ProviderConfig;
use std::str::FromStr;

/// Load retry configuration properties from a profile file
///
Expand Down Expand Up @@ -106,7 +105,7 @@ impl ProfileFileRetryConfigProvider {
let profile = match super::parser::load(&self.fs, &self.env, &self.profile_files).await {
Ok(profile) => profile,
Err(err) => {
tracing::warn!(err = %err, "failed to parse profile");
tracing::warn!(err = %DisplayErrorContext(&err), "failed to parse profile");
// return an empty builder
return Ok(RetryConfigBuilder::new());
}
Expand Down
2 changes: 1 addition & 1 deletion aws/rust-runtime/aws-config/src/sts/assume_role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ impl Inner {
}
_ => {}
}
tracing::warn!(error = ?err.message(), "sts refused to grant assume role");
tracing::warn!(error = ?err.message(), "STS refused to grant assume role");
Err(CredentialsError::provider_error(SdkError::ServiceError {
err,
raw,
Expand Down
8 changes: 4 additions & 4 deletions aws/rust-runtime/aws-config/src/web_identity_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@
//! # }
//! ```
use aws_sdk_sts::Region;
use aws_types::os_shim_internal::{Env, Fs};

use crate::provider_config::ProviderConfig;
use crate::sts;
use aws_sdk_sts::middleware::DefaultMiddleware;
use aws_sdk_sts::Region;
use aws_smithy_client::erase::DynConnector;
use aws_smithy_types::error::display::DisplayErrorContext;
use aws_types::credentials::{self, future, CredentialsError, ProvideCredentials};
use aws_types::os_shim_internal::{Env, Fs};
use std::borrow::Cow;
use std::path::{Path, PathBuf};
use tracing::Instrument;
Expand Down Expand Up @@ -251,7 +251,7 @@ async fn load_credentials(
.await
.expect("valid operation");
let resp = client.call(operation).await.map_err(|sdk_error| {
tracing::warn!(error = ?sdk_error, "sts returned an error assuming web identity role");
tracing::warn!(error = %DisplayErrorContext(&sdk_error), "STS returned an error assuming web identity role");
CredentialsError::provider_error(sdk_error)
})?;
sts::util::into_credentials(resp.credentials, "WebIdentityToken")
Expand Down
3 changes: 2 additions & 1 deletion aws/rust-runtime/aws-inlineable/src/http_body_checksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ mod tests {
use aws_smithy_checksums::ChecksumAlgorithm;
use aws_smithy_http::body::SdkBody;
use aws_smithy_http::byte_stream::ByteStream;
use aws_smithy_types::error::display::DisplayErrorContext;
use bytes::{Bytes, BytesMut};
use http_body::Body;
use std::sync::Once;
Expand Down Expand Up @@ -335,7 +336,7 @@ mod tests {

let mut validated_body = Vec::new();
if let Err(e) = tokio::io::copy(&mut body.into_async_read(), &mut validated_body).await {
tracing::error!("{}", e);
tracing::error!("{}", DisplayErrorContext(&e));
panic!("checksum validation has failed");
};
let body = std::str::from_utf8(&validated_body).unwrap();
Expand Down
3 changes: 2 additions & 1 deletion rust-runtime/aws-smithy-client/src/hyper_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ use aws_smithy_async::future::timeout::TimedOutError;
use aws_smithy_async::rt::sleep::{default_async_sleep, AsyncSleep};
use aws_smithy_http::body::SdkBody;
use aws_smithy_http::result::ConnectorError;
use aws_smithy_types::error::display::DisplayErrorContext;
use aws_smithy_types::retry::ErrorKind;
use http::Uri;
use hyper::client::connect::{Connected, Connection};
Expand Down Expand Up @@ -177,7 +178,7 @@ fn to_connector_error(err: hyper::Error) -> ConnectorError {
else if err.is_incomplete_message() {
ConnectorError::other(err.into(), Some(ErrorKind::TransientError))
} else {
tracing::warn!(err = ?err, "unrecognized error from Hyper. If this error should be retried, please file an issue.");
tracing::warn!(err = %DisplayErrorContext(&err), "unrecognized error from Hyper. If this error should be retried, please file an issue.");
ConnectorError::other(err.into(), None)
}
}
Expand Down

0 comments on commit 308b419

Please sign in to comment.