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

Make SdkError::into_service_error infallible #1974

Merged
merged 3 commits into from
Nov 16, 2022
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add From impl to convert operation errors to top-level errors
jdisanti committed Nov 15, 2022
commit d459f0439b02deb74bbabecc83f325b4827618a4
Original file line number Diff line number Diff line change
@@ -95,6 +95,7 @@ class TopLevelErrorGenerator(private val codegenContext: CodegenContext, private

private fun RustWriter.renderImplFrom(errorSymbol: RuntimeType, errors: List<ShapeId>) {
if (errors.isNotEmpty() || CodegenTarget.CLIENT == codegenContext.target) {
val operationErrors = errors.map { model.expectShape(it) }
rustBlock(
"impl<R> From<#T<#T, R>> for Error where R: Send + Sync + std::fmt::Debug + 'static",
sdkError,
@@ -106,22 +107,27 @@ class TopLevelErrorGenerator(private val codegenContext: CodegenContext, private
"OpError" to errorSymbol,
) {
rustBlock("match err") {
val operationErrors = errors.map { model.expectShape(it) }
rustBlock("#T::ServiceError(context) => match context.into_err().kind", sdkError) {
operationErrors.forEach { errorShape ->
val errSymbol = symbolProvider.toSymbol(errorShape)
rust(
"#TKind::${errSymbol.name}(inner) => Error::${errSymbol.name}(inner),",
errorSymbol,
)
}
rustTemplate(
"#{errorSymbol}Kind::Unhandled(inner) => Error::Unhandled(#{unhandled}::new(inner.into())),",
"errorSymbol" to errorSymbol,
"unhandled" to unhandledError(),
rust("#T::ServiceError(context) => Self::from(context.into_err()),", sdkError)
rust("_ => Error::Unhandled(#T::new(err.into())),", unhandledError())
}
}
}

rustBlock("impl From<#T> for Error", errorSymbol) {
rustBlock("fn from(err: #T) -> Self", errorSymbol) {
rustBlock("match err.kind") {
operationErrors.forEach { errorShape ->
val errSymbol = symbolProvider.toSymbol(errorShape)
rust(
"#TKind::${errSymbol.name}(inner) => Error::${errSymbol.name}(inner),",
errorSymbol,
)
}
rust("_ => Error::Unhandled(#T::new(err.into())),", unhandledError())
rustTemplate(
"#{errorSymbol}Kind::Unhandled(inner) => Error::Unhandled(#{unhandled}::new(inner.into())),",
"errorSymbol" to errorSymbol,
"unhandled" to unhandledError(),
)
}
}
}