-
Notifications
You must be signed in to change notification settings - Fork 193
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
Revise unhandled error variant according to RFC-39 #3191
Conversation
A new generated diff is ready to view.
A new doc preview is ready to view. |
A new generated diff is ready to view.
A new doc preview is ready to view. |
...n/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/ClientEnumGenerator.kt
Outdated
Show resolved
Hide resolved
...oftware/amazon/smithy/rust/codegen/client/smithy/generators/error/OperationErrorGenerator.kt
Outdated
Show resolved
Hide resolved
...oftware/amazon/smithy/rust/codegen/client/smithy/generators/error/OperationErrorGenerator.kt
Outdated
Show resolved
Hide resolved
...oftware/amazon/smithy/rust/codegen/client/smithy/generators/error/OperationErrorGenerator.kt
Outdated
Show resolved
Hide resolved
.../software/amazon/smithy/rust/codegen/client/smithy/generators/error/ServiceErrorGenerator.kt
Outdated
Show resolved
Hide resolved
a71467e
to
b308867
Compare
A new generated diff is ready to view.
A new doc preview is ready to view. |
A new generated diff is ready to view.
A new doc preview is ready to view. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
approved with a few comments—I think we should also workshop that deprecation message but we can do that later
@@ -36,6 +37,7 @@ impl RequestIdExt for ErrorMetadata { | |||
} | |||
} | |||
|
|||
#[allow(deprecated)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this is where I'd consider using Introspect but this is fine, I don't think it's a huge deal if we do it this way.
// An unexpected error occurred (e.g., invalid JSON returned by the service or an unknown error code). | ||
GetStorageError::Unhandled(uh) => { | ||
tracing::error!(error = %uh, "An unhandled error has occurred.") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if this is an example it should probably use DisplayErrorContext
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call. Fixed.
@@ -58,6 +61,7 @@ impl Builder { | |||
/// [`DisplayErrorContext`](crate::error::display::DisplayErrorContext), use another | |||
/// error reporter library that visits the error's cause/source chain, or call | |||
/// [`Error::source`](std::error::Error::source) for more details about the underlying cause. | |||
#[deprecated(note = "This type is no longer used by errors.")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so is this type still used at all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's no longer used. I left it in to be removed in the next release in case anyone was referencing it.
CHANGELOG.next.toml
Outdated
```rust | ||
match service_error.err() { | ||
GetStorageError::StorageAccessNotAuthorized(_) => { /* ... */ } | ||
GetStorageError::Unhandled(unhandled) if unhandled.code() == "SomeUnmodeledErrorCode" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code is optional; == Some(...)
, same for below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
While fixing examples for this, I realized we need a way to parse an enum while disallowing unknown variants. For example, this is what examples are currently doing: // parse resource type from user input
let parsed = ResourceType::from(resource_type.as_str());
if matches!(parsed, ResourceType::Unknown(_)) {
panic!(
"unknown resource type: `{}`. Valid resource types: {:#?}",
&resource_type,
ResourceType::values()
)
} I'm going to add a // parse resource type from user input
let parsed = match ResourceType::try_parse(resource_type.as_str()) {
Ok(parsed) => parsed,
Err(_) => panic!(
"unknown resource type: `{}`. Valid resource types: {:#?}",
&resource_type,
ResourceType::values()
),
}; |
Also found that |
A new generated diff is ready to view.
A new doc preview is ready to view. |
A new generated diff is ready to view.
A new doc preview is ready to view. |
Made a slight tweak to your suggested message:
Instead of "for more information" since the trait doesn't give more information about this deprecation, so that could have been confusing. |
A new generated diff is ready to view.
A new doc preview is ready to view. |
This PR implements RFC-39 with a couple slight deviations:
introspect
method is added sinceError
already implementsProvideErrorMetadata
.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.