Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revamp errors in aws-smithy-types-convert and aws-smithy-xml #1917

Merged
merged 4 commits into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -50,7 +50,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 @@ -70,7 +70,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 @@ -80,7 +80,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 @@ -32,7 +32,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 Down Expand Up @@ -61,7 +61,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 @@ -71,7 +71,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 @@ -32,7 +32,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 Down Expand Up @@ -60,7 +60,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 @@ -70,7 +70,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 @@ -42,24 +42,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 @@ -39,10 +39,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 @@ -40,13 +40,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