Commit 701547cd authored by AWS SDK Rust Bot's avatar AWS SDK Rust Bot
Browse files

[smithy-rs] Rollup of 3 commits



Includes commits:
  1297c8c7 Avoid a real connection in unit test (#3063)
  98dadc01 Make updates to default value behavior (#3064)
  8439f2ae Move `aws_smithy_http::operation::error::BuildError` into `aws-smithy-types` (#3032)

Co-authored-by: default avatarRussell Cohen <rcoh@amazon.com>
Co-authored-by: default avatarysaito1001 <awsaito@amazon.com>
parent e821df60
Loading
Loading
Loading
Loading
+10 −11
Original line number Diff line number Diff line
@@ -6,7 +6,6 @@
//! Code for resolving an endpoint (URI) that a request should be sent to

use crate::endpoint::error::InvalidEndpointError;
use crate::operation::error::BuildError;
use aws_smithy_types::config_bag::{Storable, StoreReplace};
use http::uri::{Authority, Uri};
use std::borrow::Cow;
@@ -104,15 +103,13 @@ impl<T> ResolveEndpoint<T> for Endpoint {
pub struct EndpointPrefix(String);
impl EndpointPrefix {
    /// Create a new endpoint prefix from an `impl Into<String>`. If the prefix argument is invalid,
    /// a [`BuildError`] will be returned.
    pub fn new(prefix: impl Into<String>) -> StdResult<Self, BuildError> {
    /// a [`InvalidEndpointError`] will be returned.
    pub fn new(prefix: impl Into<String>) -> StdResult<Self, InvalidEndpointError> {
        let prefix = prefix.into();
        match Authority::from_str(&prefix) {
            Ok(_) => Ok(EndpointPrefix(prefix)),
            Err(err) => Err(BuildError::invalid_uri(
                prefix,
                "invalid prefix".into(),
                err,
            Err(err) => Err(InvalidEndpointError::failed_to_construct_authority(
                prefix, err,
            )),
        }
    }
@@ -142,11 +139,13 @@ pub fn apply_endpoint(
        .map(|auth| auth.as_str())
        .unwrap_or("");
    let authority = if !prefix.is_empty() {
        Authority::from_str(&format!("{}{}", prefix, authority))
        Cow::Owned(format!("{}{}", prefix, authority))
    } else {
        Authority::from_str(authority)
    }
    .map_err(InvalidEndpointError::failed_to_construct_authority)?;
        Cow::Borrowed(authority)
    };
    let authority = Authority::from_str(&authority).map_err(|err| {
        InvalidEndpointError::failed_to_construct_authority(authority.into_owned(), err)
    })?;
    let scheme = *endpoint
        .scheme()
        .as_ref()
+17 −8
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@ impl Error for ResolveEndpointError {
pub(super) enum InvalidEndpointErrorKind {
    EndpointMustHaveScheme,
    FailedToConstructAuthority {
        authority: String,
        source: Box<dyn Error + Send + Sync + 'static>,
    },
    FailedToConstructUri {
@@ -69,23 +70,28 @@ pub struct InvalidEndpointError {
}

impl InvalidEndpointError {
    pub(super) fn endpoint_must_have_scheme() -> Self {
    /// Construct a build error for a missing scheme
    pub fn endpoint_must_have_scheme() -> Self {
        Self {
            kind: InvalidEndpointErrorKind::EndpointMustHaveScheme,
        }
    }

    pub(super) fn failed_to_construct_authority(
    /// Construct a build error for an invalid authority
    pub fn failed_to_construct_authority(
        authority: impl Into<String>,
        source: impl Into<Box<dyn Error + Send + Sync + 'static>>,
    ) -> Self {
        Self {
            kind: InvalidEndpointErrorKind::FailedToConstructAuthority {
                authority: authority.into(),
                source: source.into(),
            },
        }
    }

    pub(super) fn failed_to_construct_uri(
    /// Construct a build error for an invalid URI
    pub fn failed_to_construct_uri(
        source: impl Into<Box<dyn Error + Send + Sync + 'static>>,
    ) -> Self {
        Self {
@@ -105,11 +111,11 @@ impl From<InvalidEndpointErrorKind> for InvalidEndpointError {
impl fmt::Display for InvalidEndpointError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        use InvalidEndpointErrorKind as ErrorKind;
        match self.kind {
        match &self.kind {
            ErrorKind::EndpointMustHaveScheme => write!(f, "endpoint must contain a valid scheme"),
            ErrorKind::FailedToConstructAuthority { .. } => write!(
            ErrorKind::FailedToConstructAuthority { authority, source: _ } => write!(
                f,
                "endpoint must contain a valid authority when combined with endpoint prefix"
                "endpoint must contain a valid authority when combined with endpoint prefix: {authority}"
            ),
            ErrorKind::FailedToConstructUri { .. } => write!(f, "failed to construct URI"),
        }
@@ -120,8 +126,11 @@ impl Error for InvalidEndpointError {
    fn source(&self) -> Option<&(dyn Error + 'static)> {
        use InvalidEndpointErrorKind as ErrorKind;
        match &self.kind {
            ErrorKind::FailedToConstructUri { source }
            | ErrorKind::FailedToConstructAuthority { source } => Some(source.as_ref()),
            ErrorKind::FailedToConstructUri { source } => Some(source.as_ref()),
            ErrorKind::FailedToConstructAuthority {
                authority: _,
                source,
            } => Some(source.as_ref()),
            ErrorKind::EndpointMustHaveScheme => None,
        }
    }
+6 −1
Original line number Diff line number Diff line
@@ -9,7 +9,12 @@
use aws_smithy_types::config_bag::{Storable, StoreReplace};
use std::borrow::Cow;

pub mod error;
//TODO(runtimeCratesVersioningCleanup): Re-point those who use the following reexport to
// directly depend on `aws_smithy_types` and remove the reexport below.
/// Errors for operations
pub mod error {
    pub use aws_smithy_types::error::operation::{BuildError, SerializationError};
}

/// Metadata added to the [`ConfigBag`](aws_smithy_types::config_bag::ConfigBag) that identifies the API being called.
#[derive(Clone, Debug)]
+1 −0
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@ use std::fmt;

pub mod display;
pub mod metadata;
pub mod operation;
mod unhandled;

pub use metadata::ErrorMetadata;
+2 −27
Original line number Diff line number Diff line
@@ -5,9 +5,7 @@

//! Errors for operations

use aws_smithy_types::date_time::DateTimeFormatError;
use http::uri::InvalidUri;
use std::borrow::Cow;
use crate::date_time::DateTimeFormatError;
use std::error::Error;
use std::fmt::{Display, Formatter};

@@ -80,15 +78,6 @@ enum BuildErrorKind {
    /// The serializer could not serialize the input
    SerializationError(SerializationError),

    /// The serializer did not produce a valid URI
    ///
    /// This typically indicates that a field contained invalid characters.
    InvalidUri {
        uri: String,
        message: Cow<'static, str>,
        source: InvalidUri,
    },

    /// An error occurred request construction
    Other(Box<dyn Error + Send + Sync + 'static>),
}
@@ -104,16 +93,6 @@ pub struct BuildError {
}

impl BuildError {
    pub(crate) fn invalid_uri(uri: String, message: Cow<'static, str>, source: InvalidUri) -> Self {
        Self {
            kind: BuildErrorKind::InvalidUri {
                uri,
                message,
                source,
            },
        }
    }

    /// Construct a build error for a missing field
    pub fn missing_field(field: &'static str, details: &'static str) -> Self {
        Self {
@@ -121,7 +100,7 @@ impl BuildError {
        }
    }

    /// Construct a build error for a missing field
    /// Construct a build error for an invalid field
    pub fn invalid_field(field: &'static str, details: impl Into<String>) -> Self {
        Self {
            kind: BuildErrorKind::InvalidField {
@@ -165,9 +144,6 @@ impl Display for BuildError {
            BuildErrorKind::SerializationError(_) => {
                write!(f, "failed to serialize input")
            }
            BuildErrorKind::InvalidUri { uri, message, .. } => {
                write!(f, "generated URI `{uri}` was not a valid URI: {message}")
            }
            BuildErrorKind::Other(_) => {
                write!(f, "error during request construction")
            }
@@ -180,7 +156,6 @@ impl Error for BuildError {
        match &self.kind {
            BuildErrorKind::SerializationError(source) => Some(source as _),
            BuildErrorKind::Other(source) => Some(source.as_ref()),
            BuildErrorKind::InvalidUri { source, .. } => Some(source as _),
            BuildErrorKind::InvalidField { .. } | BuildErrorKind::MissingField { .. } => None,
        }
    }
Loading