From afa6186c3f26c1063437bddb4953d031ec15388e Mon Sep 17 00:00:00 2001 From: John DiSanti Date: Fri, 28 Oct 2022 17:50:45 -0700 Subject: [PATCH] Revamp errors in `aws-inlineable` --- .../aws-inlineable/src/presigning.rs | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/aws/rust-runtime/aws-inlineable/src/presigning.rs b/aws/rust-runtime/aws-inlineable/src/presigning.rs index 9a259d700c6..5a97a19902e 100644 --- a/aws/rust-runtime/aws-inlineable/src/presigning.rs +++ b/aws/rust-runtime/aws-inlineable/src/presigning.rs @@ -50,10 +50,8 @@ pub mod config { } } - /// `PresigningConfig` build errors. - #[non_exhaustive] #[derive(Debug)] - pub enum Error { + enum ErrorKind { /// Presigned requests cannot be valid for longer than one week. ExpiresInDurationTooLong, @@ -61,19 +59,31 @@ pub mod config { ExpiresInRequired, } + /// `PresigningConfig` build errors. + #[derive(Debug)] + pub struct Error { + kind: ErrorKind, + } + impl std::error::Error for Error {} impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - Error::ExpiresInDurationTooLong => { + match self.kind { + ErrorKind::ExpiresInDurationTooLong => { write!(f, "`expires_in` must be no longer than one week") } - Error::ExpiresInRequired => write!(f, "`expires_in` is required"), + ErrorKind::ExpiresInRequired => write!(f, "`expires_in` is required"), } } } + impl From for Error { + fn from(kind: ErrorKind) -> Self { + Self { kind } + } + } + /// Builder used to create `PresigningConfig`. #[non_exhaustive] #[derive(Default, Debug)] @@ -134,9 +144,9 @@ pub mod config { /// Builds the `PresigningConfig`. This will error if `expires_in` is not /// given, or if it's longer than one week. pub fn build(self) -> Result { - let expires_in = self.expires_in.ok_or(Error::ExpiresInRequired)?; + let expires_in = self.expires_in.ok_or(ErrorKind::ExpiresInRequired)?; if expires_in > ONE_WEEK { - return Err(Error::ExpiresInDurationTooLong); + return Err(ErrorKind::ExpiresInDurationTooLong.into()); } Ok(PresigningConfig { start_time: self.start_time.unwrap_or_else(SystemTime::now),