aws: use DisplayErrorContext when displaying SDK errors

As suggested in the aws crate documentation, wrap SDK errors with
DisplayErrorContext so their Display implementation outputs the full
context.

Improve error display from "dispatch failure" to

"dispatch failure: io error: error trying to connect: dns error: failed
to lookup address information: Name or service not known: dns error:
failed to lookup address information: Name or service not known: failed
to lookup address information: Name or service not known
(DispatchFailure(DispatchFailure { source: ConnectorError { kind: Io,
source: hyper::Error(Connect, ConnectError(\"dns error\", Custom { kind:
Uncategorized, error: \"failed to lookup address information: Name or
service not known\" })), connection: Unknown } }))"

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1638>
This commit is contained in:
Guillaume Desmottes 2024-06-26 10:43:58 +02:00
parent 3b7b2cd37b
commit 0ecbd3f953

View file

@ -9,7 +9,7 @@
use aws_config::meta::region::RegionProviderChain;
use aws_sdk_s3::{
config::{timeout::TimeoutConfig, Credentials, Region},
error::ProvideErrorMetadata,
error::{DisplayErrorContext, ProvideErrorMetadata},
primitives::{ByteStream, ByteStreamError},
};
use aws_types::sdk_config::SdkConfig;
@ -46,7 +46,9 @@ impl<E: ProvideErrorMetadata + std::error::Error> fmt::Display for WaitError<E>
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
WaitError::Cancelled => f.write_str("Cancelled"),
WaitError::FutureError(err) => write!(f, "{err}: {}", err.meta()),
WaitError::FutureError(err) => {
write!(f, "{}: {}", DisplayErrorContext(&err), err.meta())
}
}
}
}