Skip to content

Commit

Permalink
Fix the re-export in middleware mode
Browse files Browse the repository at this point in the history
  • Loading branch information
jdisanti committed Aug 18, 2023
1 parent 0b18d88 commit 4a126b7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import software.amazon.smithy.rust.codegen.client.smithy.generators.OperationCus
import software.amazon.smithy.rust.codegen.client.smithy.generators.ServiceRuntimePluginCustomization
import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ConfigCustomization
import software.amazon.smithy.rust.codegen.core.rustlang.Feature
import software.amazon.smithy.rust.codegen.core.rustlang.rust
import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType
import software.amazon.smithy.rust.codegen.core.smithy.RustCrate
Expand Down Expand Up @@ -94,18 +95,26 @@ class RequiredCustomizations : ClientCodegenDecorator {
pubUseSmithyPrimitives(codegenContext, codegenContext.model)(this)
}
rustCrate.withModule(ClientRustModule.Error) {
// TODO(enableNewSmithyRuntimeCleanup): Change SdkError to a `pub use` after changing the generic's default
rust("/// Error type returned by the client.")
if (codegenContext.smithyRuntimeMode.generateOrchestrator) {
rustTemplate(
"pub type SdkError<E> = #{SdkError}<E, #{R}>;",
"SdkError" to RuntimeType.sdkError(rc),
"R" to RuntimeType.smithyRuntimeApi(rc).resolve("client::orchestrator::HttpResponse"),
)
} else {
rustTemplate(
"pub type SdkError<E> = #{SdkError}<E, #{R}>;",
"SdkError" to RuntimeType.sdkError(rc),
"R" to RuntimeType.smithyHttp(rc).resolve("operation::Response"),
)
}
rustTemplate(
"""
pub type SdkError<E> = #{SdkError}<E, #{SdkErrorResponse}>;
pub use #{DisplayErrorContext};
pub use #{ProvideErrorMetadata};
""",
"SdkError" to RuntimeType.smithyHttp(rc).resolve("result::SdkError"),
"SdkErrorResponse" to if (codegenContext.smithyRuntimeMode.generateOrchestrator) {
RuntimeType.smithyRuntimeApi(rc).resolve("client::orchestrator::HttpResponse")
} else {
RuntimeType.HttpResponse
},
"DisplayErrorContext" to RuntimeType.smithyTypes(rc).resolve("error::display::DisplayErrorContext"),
"ProvideErrorMetadata" to RuntimeType.smithyTypes(rc).resolve("error::metadata::ProvideErrorMetadata"),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ class ServerRequiredCustomizations : ServerCodegenDecorator {

rustCrate.withModule(ServerRustModule.Types) {
pubUseSmithyPrimitives(codegenContext, codegenContext.model)(this)
// TODO(enableNewSmithyRuntimeCleanup): Remove re-export of SdkError in server and add changelog entry
rustTemplate(
"""
pub type SdkError<E> = #{SdkError}<E, #{SdkErrorResponse}>;
pub type SdkError<E> = #{SdkError}<E, #{Response}>;
pub use #{DisplayErrorContext};
""",
"SdkError" to RuntimeType.smithyHttp(rc).resolve("result::SdkError"),
"SdkErrorResponse" to RuntimeType.HttpResponse,
"Response" to RuntimeType.smithyHttp(rc).resolve("operation::Response"),
"DisplayErrorContext" to RuntimeType.smithyTypes(rc).resolve("error::display::DisplayErrorContext"),
)
}
Expand Down

0 comments on commit 4a126b7

Please sign in to comment.