diff --git a/aws/rust-runtime/aws-config/src/json_credentials.rs b/aws/rust-runtime/aws-config/src/json_credentials.rs index 8e0650ac7a7..d8d696a584a 100644 --- a/aws/rust-runtime/aws-config/src/json_credentials.rs +++ b/aws/rust-runtime/aws-config/src/json_credentials.rs @@ -36,8 +36,8 @@ impl From for InvalidJsonCredentials { } } -impl From for InvalidJsonCredentials { - fn from(err: aws_smithy_json::deserialize::Error) -> Self { +impl From for InvalidJsonCredentials { + fn from(err: aws_smithy_json::deserialize::error::DeserializeError) -> Self { InvalidJsonCredentials::JsonError(err.into()) } } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/AwsJson.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/AwsJson.kt index 8c9588ada55..42251c8629a 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/AwsJson.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/AwsJson.kt @@ -113,7 +113,7 @@ open class AwsJson( "Bytes" to RuntimeType.Bytes, "Error" to RuntimeType.GenericError(runtimeConfig), "HeaderMap" to RuntimeType.http.member("HeaderMap"), - "JsonError" to CargoDependency.smithyJson(runtimeConfig).asType().member("deserialize::Error"), + "JsonError" to CargoDependency.smithyJson(runtimeConfig).asType().member("deserialize::error::DeserializeError"), "Response" to RuntimeType.http.member("Response"), "json_errors" to RuntimeType.jsonErrors(runtimeConfig), ) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/RestJson.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/RestJson.kt index 67edb3b7fa4..27deee68e4f 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/RestJson.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/RestJson.kt @@ -67,7 +67,7 @@ open class RestJson(val codegenContext: CodegenContext) : Protocol { "Bytes" to RuntimeType.Bytes, "Error" to RuntimeType.GenericError(runtimeConfig), "HeaderMap" to RuntimeType.http.member("HeaderMap"), - "JsonError" to CargoDependency.smithyJson(runtimeConfig).asType().member("deserialize::Error"), + "JsonError" to CargoDependency.smithyJson(runtimeConfig).asType().member("deserialize::error::DeserializeError"), "Response" to RuntimeType.http.member("Response"), "json_errors" to RuntimeType.jsonErrors(runtimeConfig), ) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/JsonParserGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/JsonParserGenerator.kt index 5169242adde..8c171944c69 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/JsonParserGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/JsonParserGenerator.kt @@ -66,8 +66,8 @@ class JsonParserGenerator( private val jsonDeserModule = RustModule.private("json_deser") private val typeConversionGenerator = TypeConversionGenerator(model, symbolProvider, runtimeConfig) private val codegenScope = arrayOf( - "Error" to smithyJson.member("deserialize::Error"), - "ErrorReason" to smithyJson.member("deserialize::ErrorReason"), + "Error" to smithyJson.member("deserialize::error::DeserializeError"), + "ErrorKind" to smithyJson.member("deserialize::error::DeserializeErrorKind"), "expect_blob_or_null" to smithyJson.member("deserialize::token::expect_blob_or_null"), "expect_bool_or_null" to smithyJson.member("deserialize::token::expect_bool_or_null"), "expect_document" to smithyJson.member("deserialize::token::expect_document"), @@ -414,7 +414,7 @@ class JsonParserGenerator( if (StructureGenerator.fallibleBuilder(shape, symbolProvider)) { rustTemplate( """.map_err(|err| #{Error}::new( - #{ErrorReason}::Custom(format!("{}", err).into()), None) + #{ErrorKind}::Custom(format!("{}", err).into()), None) )?""", *codegenScope, ) diff --git a/rust-runtime/aws-smithy-http-server/src/rejection.rs b/rust-runtime/aws-smithy-http-server/src/rejection.rs index 6e4fbc8a642..fa4464cb1b9 100644 --- a/rust-runtime/aws-smithy-http-server/src/rejection.rs +++ b/rust-runtime/aws-smithy-http-server/src/rejection.rs @@ -235,7 +235,7 @@ impl From for RequestRejection { // type. Generated functions that use [crate::rejection::RequestRejection] can thus use `?` to // bubble up instead of having to sprinkle things like [`Result::map_err`] everywhere. -convert_to_request_rejection!(aws_smithy_json::deserialize::Error, JsonDeserialize); +convert_to_request_rejection!(aws_smithy_json::deserialize::error::DeserializeError, JsonDeserialize); convert_to_request_rejection!(aws_smithy_xml::decode::XmlError, XmlDeserialize); convert_to_request_rejection!(aws_smithy_http::operation::error::BuildError, Build); convert_to_request_rejection!(aws_smithy_http::header::ParseError, HeaderParse); diff --git a/rust-runtime/aws-smithy-json/src/deserialize.rs b/rust-runtime/aws-smithy-json/src/deserialize.rs index ac6d0b337cf..39d61e78f38 100644 --- a/rust-runtime/aws-smithy-json/src/deserialize.rs +++ b/rust-runtime/aws-smithy-json/src/deserialize.rs @@ -3,16 +3,15 @@ * SPDX-License-Identifier: Apache-2.0 */ +use crate::deserialize::error::{DeserializeError as Error, DeserializeErrorKind as ErrorKind}; use aws_smithy_types::Number; +use ErrorKind::*; -mod error; +pub mod error; pub mod token; -pub use error::{Error, ErrorReason}; pub use token::{EscapeError, EscapedStr, Offset, Token}; -use ErrorReason::*; - /// JSON token parser as a Rust iterator /// /// This parser will parse and yield exactly one [`Token`] per iterator `next()` call. @@ -96,13 +95,13 @@ impl<'a> JsonTokenIterator<'a> { } /// Creates an error at the given `offset` in the stream. - fn error_at(&self, offset: usize, reason: ErrorReason) -> Error { - Error::new(reason, Some(offset)) + fn error_at(&self, offset: usize, kind: ErrorKind) -> Error { + Error::new(kind, Some(offset)) } /// Creates an error at the current offset in the stream. - fn error(&self, reason: ErrorReason) -> Error { - self.error_at(self.index, reason) + fn error(&self, kind: ErrorKind) -> Error { + self.error_at(self.index, kind) } /// Advances until it hits a non-whitespace character or the end of the slice. @@ -504,11 +503,12 @@ fn must_not_be_finite(f: f64) -> Result { #[cfg(test)] mod tests { + use crate::deserialize::error::{DeserializeError as Error, DeserializeErrorKind as ErrorKind}; use crate::deserialize::token::test::{ end_array, end_object, object_key, start_array, start_object, value_bool, value_null, value_number, value_string, }; - use crate::deserialize::{json_token_iter, Error, ErrorReason, EscapedStr, Token}; + use crate::deserialize::{json_token_iter, EscapedStr, Token}; use aws_smithy_types::Number; use proptest::prelude::*; @@ -655,7 +655,7 @@ mod tests { let tokens: Vec> = json_token_iter(input).collect(); assert_eq!( vec![Err(Error::new( - ErrorReason::UnexpectedToken(token, msg), + ErrorKind::UnexpectedToken(token, msg), Some(offset) ))], tokens, @@ -667,7 +667,7 @@ mod tests { let invalid_number = |input, offset| { let tokens: Vec> = json_token_iter(input).collect(); assert_eq!( - vec![Err(Error::new(ErrorReason::InvalidNumber, Some(offset)))], + vec![Err(Error::new(ErrorKind::InvalidNumber, Some(offset)))], tokens, "input: \"{}\"", std::str::from_utf8(input).unwrap(), @@ -699,7 +699,7 @@ mod tests { assert_eq!(start_array(1), iter.next()); assert_eq!(value_null(2), iter.next()); assert_eq!( - Some(Err(Error::new(ErrorReason::UnexpectedEos, Some(7)))), + Some(Err(Error::new(ErrorKind::UnexpectedEos, Some(7)))), iter.next() ); } @@ -761,7 +761,7 @@ mod tests { assert_eq!(value_string(11, "trailing"), iter.next()); assert_eq!( Some(Err(Error::new( - ErrorReason::UnexpectedToken('}', "'\"'"), + ErrorKind::UnexpectedToken('}', "'\"'"), Some(23), ))), iter.next() @@ -775,7 +775,7 @@ mod tests { assert_eq!(start_object(1), iter.next()); assert_eq!(object_key(2, "test"), iter.next()); assert_eq!( - Some(Err(Error::new(ErrorReason::UnexpectedEos, Some(9),))), + Some(Err(Error::new(ErrorKind::UnexpectedEos, Some(9),))), iter.next() ); assert_eq!(None, iter.next()); diff --git a/rust-runtime/aws-smithy-json/src/deserialize/error.rs b/rust-runtime/aws-smithy-json/src/deserialize/error.rs index 957effcc5b1..c82d668dc86 100644 --- a/rust-runtime/aws-smithy-json/src/deserialize/error.rs +++ b/rust-runtime/aws-smithy-json/src/deserialize/error.rs @@ -8,8 +8,9 @@ use std::borrow::Cow; use std::fmt; use std::str::Utf8Error; -#[derive(Debug, PartialEq, Eq)] -pub enum ErrorReason { +#[derive(Debug)] +#[cfg_attr(test, derive(PartialEq, Eq))] +pub(in crate::deserialize) enum DeserializeErrorKind { Custom(Cow<'static, str>), ExpectedLiteral(String), InvalidEscape(char), @@ -20,73 +21,86 @@ pub enum ErrorReason { UnexpectedEos, UnexpectedToken(char, &'static str), } -use ErrorReason::*; -#[derive(Debug, PartialEq, Eq)] -pub struct Error { - reason: ErrorReason, +#[derive(Debug)] +#[cfg_attr(test, derive(PartialEq, Eq))] +pub struct DeserializeError { + kind: DeserializeErrorKind, offset: Option, } -impl Error { - pub fn new(reason: ErrorReason, offset: Option) -> Self { - Error { reason, offset } +impl DeserializeError { + pub(in crate::deserialize) fn new(kind: DeserializeErrorKind, offset: Option) -> Self { + Self { kind, offset } } /// Returns a custom error without an offset. - pub fn custom(message: impl Into>) -> Error { - Error::new(ErrorReason::Custom(message.into()), None) + pub fn custom(message: impl Into>) -> Self { + Self::new(DeserializeErrorKind::Custom(message.into()), None) } } -impl std::error::Error for Error {} +impl std::error::Error for DeserializeError { + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + use DeserializeErrorKind::*; + match &self.kind { + UnescapeFailed(source) => Some(source), + Custom(_) + | ExpectedLiteral(_) + | InvalidEscape(_) + | InvalidNumber + | InvalidUtf8 + | UnexpectedControlCharacter(_) + | UnexpectedToken(..) + | UnexpectedEos => None, + } + } +} -impl fmt::Display for Error { +impl fmt::Display for DeserializeError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + use DeserializeErrorKind::*; if let Some(offset) = self.offset { write!(f, "Error at offset {}: ", offset)?; } - match &self.reason { - Custom(msg) => write!(f, "failed to parse JSON: {}", msg), - ExpectedLiteral(literal) => write!(f, "expected literal: {}", literal), - InvalidEscape(escape) => write!(f, "invalid JSON escape: \\{}", escape), + match &self.kind { + Custom(msg) => write!(f, "failed to parse JSON: {msg}"), + ExpectedLiteral(literal) => write!(f, "expected literal: {literal}"), + InvalidEscape(escape) => write!(f, "invalid JSON escape: \\{escape}"), InvalidNumber => write!(f, "invalid number"), InvalidUtf8 => write!(f, "invalid UTF-8 codepoint in JSON stream"), - UnescapeFailed(err) => write!(f, "failed to unescape JSON string: {}", err), + UnescapeFailed(_) => write!(f, "failed to unescape JSON string"), UnexpectedControlCharacter(value) => write!( f, - "encountered unescaped control character in string: 0x{:X}", - value - ), - UnexpectedToken(token, expected) => write!( - f, - "unexpected token '{}'. Expected one of {}", - token, expected + "encountered unescaped control character in string: 0x{value:X}" ), + UnexpectedToken(token, expected) => { + write!(f, "unexpected token '{token}'. Expected one of {expected}",) + } UnexpectedEos => write!(f, "unexpected end of stream"), } } } -impl From for ErrorReason { +impl From for DeserializeErrorKind { fn from(_: Utf8Error) -> Self { - InvalidUtf8 + DeserializeErrorKind::InvalidUtf8 } } -impl From for Error { +impl From for DeserializeError { fn from(err: EscapeError) -> Self { - Error { - reason: ErrorReason::UnescapeFailed(err), + Self { + kind: DeserializeErrorKind::UnescapeFailed(err), offset: None, } } } -impl From for Error { +impl From for DeserializeError { fn from(_: aws_smithy_types::TryFromNumberError) -> Self { - Error { - reason: ErrorReason::InvalidNumber, + Self { + kind: DeserializeErrorKind::InvalidNumber, offset: None, } } diff --git a/rust-runtime/aws-smithy-json/src/deserialize/token.rs b/rust-runtime/aws-smithy-json/src/deserialize/token.rs index 6525651828e..c8119e59762 100644 --- a/rust-runtime/aws-smithy-json/src/deserialize/token.rs +++ b/rust-runtime/aws-smithy-json/src/deserialize/token.rs @@ -3,15 +3,14 @@ * SPDX-License-Identifier: Apache-2.0 */ -use crate::deserialize::error::{Error, ErrorReason}; +use crate::deserialize::error::{DeserializeError as Error, DeserializeErrorKind as ErrorKind}; +use crate::deserialize::must_not_be_finite; use crate::escape::unescape_string; +pub use crate::escape::EscapeError; use aws_smithy_types::date_time::Format; +use aws_smithy_types::primitive::Parse; use aws_smithy_types::{base64, Blob, DateTime, Document, Number}; use std::borrow::Cow; - -use crate::deserialize::must_not_be_finite; -pub use crate::escape::EscapeError; -use aws_smithy_types::primitive::Parse; use std::collections::HashMap; use std::iter::Peekable; @@ -44,7 +43,7 @@ pub struct Offset(pub usize); impl Offset { /// Creates a custom error from the offset pub fn error(&self, msg: Cow<'static, str>) -> Error { - Error::new(ErrorReason::Custom(msg), Some(self.0)) + Error::new(ErrorKind::Custom(msg), Some(self.0)) } } @@ -117,7 +116,7 @@ macro_rules! expect_fn { Err(token.error(Cow::Borrowed(concat!("expected ", stringify!($token))))) } None => Err(Error::new( - ErrorReason::Custom(Cow::Borrowed(concat!("expected ", stringify!($token)))), + ErrorKind::Custom(Cow::Borrowed(concat!("expected ", stringify!($token)))), None, )), } @@ -168,7 +167,7 @@ pub fn expect_number_or_null( Some(Token::ValueNumber { value, .. }) => Ok(Some(value)), Some(Token::ValueString { value, offset }) => match value.to_unescaped() { Err(err) => Err(Error::new( - ErrorReason::Custom(format!("expected a valid string, escape was invalid: {}", err).into()), Some(offset.0)) + ErrorKind::Custom(format!("expected a valid string, escape was invalid: {}", err).into()), Some(offset.0)) ), Ok(v) => f64::parse_smithy_primitive(v.as_ref()) // disregard the exact error @@ -179,7 +178,7 @@ pub fn expect_number_or_null( // convert to a helpful error .map_err(|_| { Error::new( - ErrorReason::Custom(Cow::Owned(format!( + ErrorKind::Custom(Cow::Owned(format!( "only `Infinity`, `-Infinity`, `NaN` can represent a float as a string but found `{}`", v ))), @@ -199,7 +198,7 @@ pub fn expect_blob_or_null(token: Option, Error>>) -> Result Some(Blob::new(base64::decode(value.as_escaped_str()).map_err( |err| { Error::new( - ErrorReason::Custom(Cow::Owned(format!("failed to decode base64: {}", err))), + ErrorKind::Custom(Cow::Owned(format!("failed to decode base64: {}", err))), None, ) }, @@ -221,14 +220,12 @@ pub fn expect_timestamp_or_null( .map(|v| { if v.is_nan() { Err(Error::new( - ErrorReason::Custom(Cow::Owned("NaN is not a valid epoch".to_string())), + ErrorKind::Custom(Cow::Owned("NaN is not a valid epoch".to_string())), None, )) } else if v.is_infinite() { Err(Error::new( - ErrorReason::Custom(Cow::Owned( - "Infinity is not a valid epoch".to_string(), - )), + ErrorKind::Custom(Cow::Owned("Infinity is not a valid epoch".to_string())), None, )) } else { @@ -241,7 +238,7 @@ pub fn expect_timestamp_or_null( .transpose() .map_err(|err| { Error::new( - ErrorReason::Custom(Cow::Owned(format!("failed to parse timestamp: {}", err))), + ErrorKind::Custom(Cow::Owned(format!("failed to parse timestamp: {}", err))), None, ) })?, @@ -359,7 +356,7 @@ fn skip_inner<'a>( #[cfg(test)] pub mod test { use super::*; - use crate::deserialize::error::ErrorReason::UnexpectedToken; + use crate::deserialize::error::DeserializeErrorKind::UnexpectedToken; use crate::deserialize::json_token_iter; pub fn start_array<'a>(offset: usize) -> Option, Error>> { @@ -512,7 +509,7 @@ pub mod test { fn test_expect_start_object() { assert_eq!( Err(Error::new( - ErrorReason::Custom("expected StartObject".into()), + ErrorKind::Custom("expected StartObject".into()), Some(2) )), expect_start_object(value_bool(2, true)) @@ -524,7 +521,7 @@ pub mod test { fn test_expect_start_array() { assert_eq!( Err(Error::new( - ErrorReason::Custom("expected StartArray".into()), + ErrorKind::Custom("expected StartArray".into()), Some(2) )), expect_start_array(value_bool(2, true)) @@ -563,7 +560,7 @@ pub mod test { expect_number_or_null(value_string(0, "Infinity")) ); assert_eq!( - Err(Error::new(ErrorReason::Custom("only `Infinity`, `-Infinity`, `NaN` can represent a float as a string but found `123`".into()), Some(0))), + Err(Error::new(ErrorKind::Custom("only `Infinity`, `-Infinity`, `NaN` can represent a float as a string but found `123`".into()), Some(0))), expect_number_or_null(value_string(0, "123")) ); match expect_number_or_null(value_string(0, "NaN")) { @@ -598,7 +595,7 @@ pub mod test { for &invalid in &["NaN", "Infinity", "-Infinity"] { assert_eq!( Err(Error::new( - ErrorReason::Custom(Cow::Owned(format!( + ErrorKind::Custom(Cow::Owned(format!( "{} is not a valid epoch", invalid.replace("-", "") ))), @@ -623,7 +620,7 @@ pub mod test { expect_timestamp_or_null(value_string(0, "2015-10-21T07:28:00Z"), Format::DateTime) ); let err = Error::new( - ErrorReason::Custom( + ErrorKind::Custom( "only `Infinity`, `-Infinity`, `NaN` can represent a float as a string but found `wrong`".into(), ), Some(0), diff --git a/rust-runtime/aws-smithy-json/src/escape.rs b/rust-runtime/aws-smithy-json/src/escape.rs index 08ea6ae3cb1..4643880a66f 100644 --- a/rust-runtime/aws-smithy-json/src/escape.rs +++ b/rust-runtime/aws-smithy-json/src/escape.rs @@ -7,7 +7,7 @@ use std::borrow::Cow; use std::fmt; #[derive(Debug, PartialEq, Eq)] -pub enum EscapeError { +enum EscapeErrorKind { ExpectedSurrogatePair(String), InvalidEscapeCharacter(char), InvalidSurrogatePair(u16, u16), @@ -16,12 +16,18 @@ pub enum EscapeError { UnexpectedEndOfString, } +#[derive(Debug)] +#[cfg_attr(test, derive(PartialEq, Eq))] +pub struct EscapeError { + kind: EscapeErrorKind, +} + impl std::error::Error for EscapeError {} impl fmt::Display for EscapeError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - use EscapeError::*; - match self { + use EscapeErrorKind::*; + match &self.kind { ExpectedSurrogatePair(low) => { write!( f, @@ -40,6 +46,12 @@ impl fmt::Display for EscapeError { } } +impl From for EscapeError { + fn from(kind: EscapeErrorKind) -> Self { + Self { kind } + } +} + /// Escapes a string for embedding in a JSON string value. pub fn escape_string(value: &str) -> Cow { let bytes = value.as_bytes(); @@ -102,7 +114,7 @@ fn unescape_string_inner(start: &[u8], rest: &[u8]) -> Result { index += 1; if index == rest.len() { - return Err(EscapeError::UnexpectedEndOfString); + return Err(EscapeErrorKind::UnexpectedEndOfString.into()); } match rest[index] { b'u' => { @@ -119,7 +131,11 @@ fn unescape_string_inner(start: &[u8], rest: &[u8]) -> Result unescaped.push(b'\n'), b'r' => unescaped.push(b'\r'), b't' => unescaped.push(b'\t'), - _ => return Err(EscapeError::InvalidEscapeCharacter(byte.into())), + _ => { + return Err( + EscapeErrorKind::InvalidEscapeCharacter(byte.into()).into() + ) + } } index += 1; } @@ -132,7 +148,7 @@ fn unescape_string_inner(start: &[u8], rest: &[u8]) -> Result bool { @@ -145,24 +161,26 @@ fn is_utf16_high_surrogate(codepoint: u16) -> bool { fn read_codepoint(rest: &[u8]) -> Result { if rest.len() < 6 { - return Err(EscapeError::UnexpectedEndOfString); + return Err(EscapeErrorKind::UnexpectedEndOfString.into()); } if &rest[0..2] != b"\\u" { // The first codepoint is always prefixed with "\u" since unescape_string_inner does // that check, so this error will always be for the low word of a surrogate pair. - return Err(EscapeError::ExpectedSurrogatePair( + return Err(EscapeErrorKind::ExpectedSurrogatePair( String::from_utf8_lossy(&rest[0..6]).into(), - )); + ) + .into()); } - let codepoint_str = std::str::from_utf8(&rest[2..6]).map_err(|_| EscapeError::InvalidUtf8)?; + let codepoint_str = + std::str::from_utf8(&rest[2..6]).map_err(|_| EscapeErrorKind::InvalidUtf8)?; // Error on characters `u16::from_str_radix` would otherwise accept, such as `+` if codepoint_str .bytes() .any(|byte| !matches!(byte, b'0'..=b'9' | b'a'..=b'f' | b'A'..=b'F')) { - return Err(EscapeError::InvalidUnicodeEscape(codepoint_str.into())); + return Err(EscapeErrorKind::InvalidUnicodeEscape(codepoint_str.into()).into()); } Ok(u16::from_str_radix(codepoint_str, 16).expect("hex string is valid 16-bit value")) } @@ -174,16 +192,16 @@ fn read_unicode_escapes(bytes: &[u8], into: &mut Vec) -> Result) -> Result Result { + pub(crate) fn deserialize_partitions( + value: &[u8], + ) -> Result { let mut tokens_owned = json_token_iter(value).peekable(); let tokens = &mut tokens_owned; expect_start_object(tokens.next())?; @@ -234,7 +236,7 @@ mod deser { _ => skip_value(tokens)?, }, other => { - return Err(Error::custom(format!( + return Err(DeserializeError::custom(format!( "expected object key or end object, found: {:?}", other ))) @@ -242,18 +244,18 @@ mod deser { } } if tokens.next().is_some() { - return Err(Error::custom( + return Err(DeserializeError::custom( "found more JSON tokens after completing parsing", )); } - resolver.ok_or_else(|| Error::custom("did not find partitions array")) + resolver.ok_or_else(|| DeserializeError::custom("did not find partitions array")) } fn deser_partitions<'a, I>( tokens: &mut std::iter::Peekable, - ) -> Result, Error> + ) -> Result, DeserializeError> where - I: Iterator, Error>>, + I: Iterator, DeserializeError>>, { match tokens.next().transpose()? { Some(Token::StartArray { .. }) => { @@ -271,15 +273,15 @@ mod deser { } Ok(items) } - _ => Err(Error::custom("expected start array")), + _ => Err(DeserializeError::custom("expected start array")), } } pub(crate) fn deser_partition<'a, I>( tokens: &mut std::iter::Peekable, - ) -> Result + ) -> Result where - I: Iterator, Error>>, + I: Iterator, DeserializeError>>, { match tokens.next().transpose()? { Some(Token::StartObject { .. }) => { @@ -295,7 +297,7 @@ mod deser { builder.region_regex = token_to_str(tokens.next())? .map(|region_regex| Regex::new(®ion_regex)) .transpose() - .map_err(|e| Error::custom("invalid regex"))?; + .map_err(|e| DeserializeError::custom("invalid regex"))?; } "regions" => { builder.regions = deser_explicit_regions(tokens)?; @@ -306,7 +308,7 @@ mod deser { _ => skip_value(tokens)?, }, other => { - return Err(Error::custom(format!( + return Err(DeserializeError::custom(format!( "expected object key or end object, found: {:?}", other ))) @@ -315,16 +317,16 @@ mod deser { } Ok(builder.build()) } - _ => Err(Error::custom("expected start object")), + _ => Err(DeserializeError::custom("expected start object")), } } #[allow(clippy::type_complexity, non_snake_case)] pub(crate) fn deser_explicit_regions<'a, I>( tokens: &mut std::iter::Peekable, - ) -> Result, Error> + ) -> Result, DeserializeError> where - I: Iterator, Error>>, + I: Iterator, DeserializeError>>, { match tokens.next().transpose()? { Some(Token::StartObject { .. }) => { @@ -340,7 +342,7 @@ mod deser { } } other => { - return Err(Error::custom(format!( + return Err(DeserializeError::custom(format!( "expected object key or end object, found: {:?}", other ))) @@ -349,12 +351,14 @@ mod deser { } Ok(map) } - _ => Err(Error::custom("expected start object")), + _ => Err(DeserializeError::custom("expected start object")), } } /// Convert a token to `Str` (a potentially static String) - fn token_to_str(token: Option>) -> Result, Error> { + fn token_to_str( + token: Option>, + ) -> Result, DeserializeError> { Ok(expect_string_or_null(token)? .map(|s| s.to_unescaped().map(|u| u.into_owned())) .transpose()? @@ -363,9 +367,9 @@ mod deser { fn deser_outputs<'a, I>( tokens: &mut std::iter::Peekable, - ) -> Result, Error> + ) -> Result, DeserializeError> where - I: Iterator, Error>>, + I: Iterator, DeserializeError>>, { match tokens.next().transpose()? { Some(Token::StartObject { .. }) => { @@ -393,7 +397,7 @@ mod deser { _ => skip_value(tokens)?, }, other => { - return Err(Error::custom(format!( + return Err(DeserializeError::custom(format!( "expected object key or end object, found: {:?}", other ))) @@ -402,7 +406,7 @@ mod deser { } Ok(Some(builder)) } - _ => Err(Error::custom("expected start object")), + _ => Err(DeserializeError::custom("expected start object")), } } } diff --git a/rust-runtime/inlineable/src/json_errors.rs b/rust-runtime/inlineable/src/json_errors.rs index f20c16b1c28..ea13da3ba82 100644 --- a/rust-runtime/inlineable/src/json_errors.rs +++ b/rust-runtime/inlineable/src/json_errors.rs @@ -4,7 +4,7 @@ */ use aws_smithy_json::deserialize::token::skip_value; -use aws_smithy_json::deserialize::{json_token_iter, Error as DeserializeError, Token}; +use aws_smithy_json::deserialize::{error::DeserializeError, json_token_iter, Token}; use aws_smithy_types::Error as SmithyError; use bytes::Bytes; use http::header::ToStrError;