Unverified Commit 8dfe5a1f authored by John DiSanti's avatar John DiSanti Committed by GitHub
Browse files

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

parent e36d3469
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -96,7 +96,7 @@ 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,
    )
@@ -104,7 +104,7 @@ class S3(codegenContext: CodegenContext) : RestXml(codegenContext) {
    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(
+3 −3
Original line number Diff line number Diff line
@@ -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")

@@ -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)
@@ -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)
+3 −3
Original line number Diff line number Diff line
@@ -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")

@@ -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)
@@ -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)
+3 −3
Original line number Diff line number Diff line
@@ -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")

@@ -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)
@@ -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)
+5 −5
Original line number Diff line number Diff line
@@ -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
Loading