Skip to content

Commit

Permalink
Revamp errors in aws-smithy-xml
Browse files Browse the repository at this point in the history
  • Loading branch information
jdisanti committed Nov 1, 2022
1 parent 719c028 commit a156037
Show file tree
Hide file tree
Showing 19 changed files with 171 additions and 142 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ class S3(codegenContext: CodegenContext) : RestXml(codegenContext) {
"Error" to RuntimeType.GenericError(runtimeConfig),
"HeaderMap" to RuntimeType.http.member("HeaderMap"),
"Response" to RuntimeType.http.member("Response"),
"XmlError" to CargoDependency.smithyXml(runtimeConfig).asType().member("decode::XmlError"),
"XmlDecodeError" to CargoDependency.smithyXml(runtimeConfig).asType().member("decode::XmlDecodeError"),
"base_errors" to restXmlErrors,
"s3_errors" to AwsRuntimeType.S3Errors,
)

override fun parseHttpGenericError(operationShape: OperationShape): RuntimeType {
return RuntimeType.forInlineFun("parse_http_generic_error", RustModule.private("xml_deser")) {
rustBlockTemplate(
"pub fn parse_http_generic_error(response: &#{Response}<#{Bytes}>) -> Result<#{Error}, #{XmlError}>",
"pub fn parse_http_generic_error(response: &#{Response}<#{Bytes}>) -> Result<#{Error}, #{XmlDecodeError}>",
*errorScope,
) {
rustTemplate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class AwsQueryProtocol(private val codegenContext: CodegenContext) : Protocol {
"Error" to RuntimeType.GenericError(runtimeConfig),
"HeaderMap" to RuntimeType.http.member("HeaderMap"),
"Response" to RuntimeType.http.member("Response"),
"XmlError" to CargoDependency.smithyXml(runtimeConfig).asType().member("decode::XmlError"),
"XmlDecodeError" to CargoDependency.smithyXml(runtimeConfig).asType().member("decode::XmlDecodeError"),
)
private val xmlDeserModule = RustModule.private("xml_deser")

Expand All @@ -64,7 +64,7 @@ class AwsQueryProtocol(private val codegenContext: CodegenContext) : Protocol {
override fun parseHttpGenericError(operationShape: OperationShape): RuntimeType =
RuntimeType.forInlineFun("parse_http_generic_error", xmlDeserModule) {
rustBlockTemplate(
"pub fn parse_http_generic_error(response: &#{Response}<#{Bytes}>) -> Result<#{Error}, #{XmlError}>",
"pub fn parse_http_generic_error(response: &#{Response}<#{Bytes}>) -> Result<#{Error}, #{XmlDecodeError}>",
*errorScope,
) {
rust("#T::parse_generic_error(response.body().as_ref())", awsQueryErrors)
Expand All @@ -74,7 +74,7 @@ class AwsQueryProtocol(private val codegenContext: CodegenContext) : Protocol {
override fun parseEventStreamGenericError(operationShape: OperationShape): RuntimeType =
RuntimeType.forInlineFun("parse_event_stream_generic_error", xmlDeserModule) {
rustBlockTemplate(
"pub fn parse_event_stream_generic_error(payload: &#{Bytes}) -> Result<#{Error}, #{XmlError}>",
"pub fn parse_event_stream_generic_error(payload: &#{Bytes}) -> Result<#{Error}, #{XmlDecodeError}>",
*errorScope,
) {
rust("#T::parse_generic_error(payload.as_ref())", awsQueryErrors)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Ec2QueryProtocol(private val codegenContext: CodegenContext) : Protocol {
"Error" to RuntimeType.GenericError(runtimeConfig),
"HeaderMap" to RuntimeType.http.member("HeaderMap"),
"Response" to RuntimeType.http.member("Response"),
"XmlError" to CargoDependency.smithyXml(runtimeConfig).asType().member("decode::XmlError"),
"XmlDecodeError" to CargoDependency.smithyXml(runtimeConfig).asType().member("decode::XmlDecodeError"),
)
private val xmlDeserModule = RustModule.private("xml_deser")

Expand All @@ -55,7 +55,7 @@ class Ec2QueryProtocol(private val codegenContext: CodegenContext) : Protocol {
override fun parseHttpGenericError(operationShape: OperationShape): RuntimeType =
RuntimeType.forInlineFun("parse_http_generic_error", xmlDeserModule) {
rustBlockTemplate(
"pub fn parse_http_generic_error(response: &#{Response}<#{Bytes}>) -> Result<#{Error}, #{XmlError}>",
"pub fn parse_http_generic_error(response: &#{Response}<#{Bytes}>) -> Result<#{Error}, #{XmlDecodeError}>",
*errorScope,
) {
rust("#T::parse_generic_error(response.body().as_ref())", ec2QueryErrors)
Expand All @@ -65,7 +65,7 @@ class Ec2QueryProtocol(private val codegenContext: CodegenContext) : Protocol {
override fun parseEventStreamGenericError(operationShape: OperationShape): RuntimeType =
RuntimeType.forInlineFun("parse_event_stream_generic_error", xmlDeserModule) {
rustBlockTemplate(
"pub fn parse_event_stream_generic_error(payload: &#{Bytes}) -> Result<#{Error}, #{XmlError}>",
"pub fn parse_event_stream_generic_error(payload: &#{Bytes}) -> Result<#{Error}, #{XmlDecodeError}>",
*errorScope,
) {
rust("#T::parse_generic_error(payload.as_ref())", ec2QueryErrors)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ open class RestXml(val codegenContext: CodegenContext) : Protocol {
"Error" to RuntimeType.GenericError(runtimeConfig),
"HeaderMap" to RuntimeType.http.member("HeaderMap"),
"Response" to RuntimeType.http.member("Response"),
"XmlError" to CargoDependency.smithyXml(runtimeConfig).asType().member("decode::XmlError"),
"XmlDecodeError" to CargoDependency.smithyXml(runtimeConfig).asType().member("decode::XmlDecodeError"),
)
private val xmlDeserModule = RustModule.private("xml_deser")

Expand All @@ -55,7 +55,7 @@ open class RestXml(val codegenContext: CodegenContext) : Protocol {
override fun parseHttpGenericError(operationShape: OperationShape): RuntimeType =
RuntimeType.forInlineFun("parse_http_generic_error", xmlDeserModule) {
rustBlockTemplate(
"pub fn parse_http_generic_error(response: &#{Response}<#{Bytes}>) -> Result<#{Error}, #{XmlError}>",
"pub fn parse_http_generic_error(response: &#{Response}<#{Bytes}>) -> Result<#{Error}, #{XmlDecodeError}>",
*errorScope,
) {
rust("#T::parse_generic_error(response.body().as_ref())", restXmlErrors)
Expand All @@ -65,7 +65,7 @@ open class RestXml(val codegenContext: CodegenContext) : Protocol {
override fun parseEventStreamGenericError(operationShape: OperationShape): RuntimeType =
RuntimeType.forInlineFun("parse_event_stream_generic_error", xmlDeserModule) {
rustBlockTemplate(
"pub fn parse_event_stream_generic_error(payload: &#{Bytes}) -> Result<#{Error}, #{XmlError}>",
"pub fn parse_event_stream_generic_error(payload: &#{Bytes}) -> Result<#{Error}, #{XmlDecodeError}>",
*errorScope,
) {
rust("#T::parse_generic_error(payload.as_ref())", restXmlErrors)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,24 @@ class AwsQueryParserGenerator(
rustTemplate(
"""
if !(${XmlBindingTraitParserGenerator.XmlName(responseWrapperName).matchExpression("start_el")}) {
return Err(#{XmlError}::custom(format!("invalid root, expected $responseWrapperName got {:?}", start_el)))
return Err(#{XmlDecodeError}::custom(format!("invalid root, expected $responseWrapperName got {:?}", start_el)))
}
if let Some(mut result_tag) = decoder.next_tag() {
let start_el = result_tag.start_el();
if !(${XmlBindingTraitParserGenerator.XmlName(resultWrapperName).matchExpression("start_el")}) {
return Err(#{XmlError}::custom(format!("invalid result, expected $resultWrapperName got {:?}", start_el)))
return Err(#{XmlDecodeError}::custom(format!("invalid result, expected $resultWrapperName got {:?}", start_el)))
}
""",
"XmlError" to context.xmlErrorType,
"XmlDecodeError" to context.xmlDecodeErrorType,
)
inner("result_tag")
rustTemplate(
"""
} else {
return Err(#{XmlError}::custom("expected $resultWrapperName tag"))
return Err(#{XmlDecodeError}::custom("expected $resultWrapperName tag"))
};
""",
"XmlError" to context.xmlErrorType,
"XmlDecodeError" to context.xmlDecodeErrorType,
)
},
) : StructuredDataParserGenerator by xmlBindingTraitParserGenerator
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ class Ec2QueryParserGenerator(
rustTemplate(
"""
if !(${XmlBindingTraitParserGenerator.XmlName(responseWrapperName).matchExpression("start_el")}) {
return Err(#{XmlError}::custom(format!("invalid root, expected $responseWrapperName got {:?}", start_el)))
return Err(#{XmlDecodeError}::custom(format!("invalid root, expected $responseWrapperName got {:?}", start_el)))
}
""",
"XmlError" to context.xmlErrorType,
"XmlDecodeError" to context.xmlDecodeErrorType,
)
inner("decoder")
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ class RestXmlParserGenerator(
"""
if !${XmlBindingTraitParserGenerator.XmlName(shapeName).matchExpression("start_el")} {
return Err(
#{XmlError}::custom(
#{XmlDecodeError}::custom(
format!("encountered invalid XML root: expected $shapeName but got {:?}. This is likely a bug in the SDK.", start_el)
)
)
}
""",
"XmlError" to context.xmlErrorType,
"XmlDecodeError" to context.xmlDecodeErrorType,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface StructuredDataParserGenerator {
* Entry point for payload-based parsing.
* Roughly:
* ```rust
* fn parse_my_struct(input: &[u8]) -> Result<MyStruct, XmlError> {
* fn parse_my_struct(input: &[u8]) -> Result<MyStruct, XmlDecodeError> {
* ...
* }
* ```
Expand All @@ -29,7 +29,7 @@ interface StructuredDataParserGenerator {
* through:
*
* ```rust
* fn parse_some_operation(inp: &[u8], builder: my_operation::Builder) -> Result<my_operation::Builder, XmlError> {
* fn parse_some_operation(inp: &[u8], builder: my_operation::Builder) -> Result<my_operation::Builder, XmlDecodeError> {
* ...
* }
* ```
Expand All @@ -41,7 +41,7 @@ interface StructuredDataParserGenerator {
* through:
*
* ```rust
* fn parse_some_error(inp: &[u8], builder: my_operation::Builder) -> Result<my_operation::Builder, XmlError> {
* fn parse_some_error(inp: &[u8], builder: my_operation::Builder) -> Result<my_operation::Builder, XmlDecodeError> {
* ...
* }
*/
Expand Down
Loading

0 comments on commit a156037

Please sign in to comment.