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

Revise unhandled error variant according to RFC-39 (#3191)

This PR implements
[RFC-39](https://github.com/smithy-lang/smithy-rs/blob/main/design/src/rfcs/rfc0039_forward_compatible_errors.md)
with a couple slight deviations:
- No `introspect` method is added since `Error` already implements
`ProvideErrorMetadata`.
- The same opaqueness and deprecation pointer is applied to the enum
unknown variant for consistency.

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
parent c0f72fbf
Loading
Loading
Loading
Loading
+58 −0
Original line number Diff line number Diff line
@@ -119,3 +119,61 @@ message = "Remove deprecated error kind type aliases."
references = ["smithy-rs#3189"]
meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "client" }
author = "jdisanti"

[[aws-sdk-rust]]
message = """
Unhandled errors have been made opaque to ensure code is written in a future-proof manner. Where previously, you
might have:
```rust
match service_error.err() {
    GetStorageError::StorageAccessNotAuthorized(_) => { /* ... */ }
    GetStorageError::Unhandled(unhandled) if unhandled.code() == Some("SomeUnmodeledErrorCode") {
        // unhandled error handling
    }
    _ => { /* ... */ }
}
```
It should now look as follows:
```rust
match service_error.err() {
    GetStorageError::StorageAccessNotAuthorized(_) => { /* ... */ }
    err if err.code() == Some("SomeUnmodeledErrorCode") {
        // unhandled error handling
    }
    _ => { /* ... */ }
}
```
The `Unhandled` variant should never be referenced directly.
"""
references = ["smithy-rs#3191"]
meta = { "breaking" = true, "tada" = false, "bug" = false }
author = "jdisanti"

[[smithy-rs]]
message = """
Unhandled errors have been made opaque to ensure code is written in a future-proof manner. Where previously, you
might have:
```rust
match service_error.err() {
    GetStorageError::StorageAccessNotAuthorized(_) => { /* ... */ }
    GetStorageError::Unhandled(unhandled) if unhandled.code() == Some("SomeUnmodeledErrorCode") {
        // unhandled error handling
    }
    _ => { /* ... */ }
}
```
It should now look as follows:
```rust
match service_error.err() {
    GetStorageError::StorageAccessNotAuthorized(_) => { /* ... */ }
    err if err.code() == Some("SomeUnmodeledErrorCode") {
        // unhandled error handling
    }
    _ => { /* ... */ }
}
```
The `Unhandled` variant should never be referenced directly.
"""
references = ["smithy-rs#3191"]
meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "client" }
author = "jdisanti"
+2 −0
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@ use aws_smithy_runtime_api::http::{Headers, Response};
use aws_smithy_types::error::metadata::{
    Builder as ErrorMetadataBuilder, ErrorMetadata, ProvideErrorMetadata,
};
#[allow(deprecated)]
use aws_smithy_types::error::Unhandled;

const EXTENDED_REQUEST_ID: &str = "s3_extended_request_id";
@@ -36,6 +37,7 @@ impl RequestIdExt for ErrorMetadata {
    }
}

#[allow(deprecated)]
impl RequestIdExt for Unhandled {
    fn extended_request_id(&self) -> Option<&str> {
        self.meta().extended_request_id()
+3 −0
Original line number Diff line number Diff line
@@ -11,6 +11,8 @@ use aws_smithy_runtime_api::http::Response;
use aws_smithy_types::error::metadata::{
    Builder as ErrorMetadataBuilder, ErrorMetadata, ProvideErrorMetadata,
};

#[allow(deprecated)]
use aws_smithy_types::error::Unhandled;

/// Constant for the [`ErrorMetadata`] extra field that contains the request ID
@@ -38,6 +40,7 @@ impl RequestId for ErrorMetadata {
    }
}

#[allow(deprecated)]
impl RequestId for Unhandled {
    fn request_id(&self) -> Option<&str> {
        self.meta().request_id()
+1 −1
Original line number Diff line number Diff line
@@ -146,7 +146,7 @@ abstract class BaseRequestIdDecorator : ClientCodegenDecorator {
                                    val sym = codegenContext.symbolProvider.toSymbol(error)
                                    rust("Self::${sym.name}(e) => #T,", wrapped)
                                }
                                rust("Self::Unhandled(e) => e.$accessorFunctionName(),")
                                rust("Self::Unhandled(e) => e.meta.$accessorFunctionName(),")
                            }
                        }
                    }
+1 −0
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@ use aws_sdk_lambda::operation::RequestId;
use aws_sdk_lambda::{Client, Config};
use aws_smithy_runtime::client::http::test_util::infallible_client_fn;

#[allow(deprecated)]
async fn run_test(
    response: impl Fn() -> http::Response<&'static str> + Send + Sync + 'static,
    expect_error: bool,
Loading