diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/UnhandledErrorGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/UnhandledErrorGenerator.kt index 88e720d2c0e..a08a849b7d5 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/UnhandledErrorGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/UnhandledErrorGenerator.kt @@ -7,8 +7,7 @@ package software.amazon.smithy.rust.codegen.core.smithy.generators.error import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.rustlang.docs -import software.amazon.smithy.rust.codegen.core.rustlang.rust -import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType internal fun unhandledError(): RuntimeType = RuntimeType.forInlineFun("Unhandled", RustModule.Error) { @@ -19,23 +18,28 @@ internal fun unhandledError(): RuntimeType = RuntimeType.forInlineFun("Unhandled Call [`Error::source`](std::error::Error::source) for more details about the underlying cause. """, ) - rust("##[derive(Debug)]") - rustBlock("pub struct Unhandled") { - rust("source: Box", RuntimeType.StdError) - } - rustBlock("impl Unhandled") { - rustBlock("pub(crate) fn new(source: Box) -> Self", RuntimeType.StdError) { - rust("Self { source }") + rustTemplate( + """ + ##[derive(Debug)] + pub struct Unhandled { + source: Box, + } + impl Unhandled { + pub(crate) fn new(source: Box) -> Self { + Self { source } + } } - } - rustBlock("impl std::fmt::Display for Unhandled") { - rustBlock("fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error>") { - rust("write!(f, \"unhandled error\")") + impl std::fmt::Display for Unhandled { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { + write!(f, "unhandled error") + } } - } - rustBlock("impl std::error::Error for Unhandled") { - rustBlock("fn source(&self) -> Option<&(dyn std::error::Error + 'static)>") { - rust("Some(self.source.as_ref() as _)") + impl #{StdError} for Unhandled { + fn source(&self) -> Option<&(dyn #{StdError} + 'static)> { + Some(self.source.as_ref() as _) + } } - } + """, + "StdError" to RuntimeType.StdError, + ) } diff --git a/rust-runtime/aws-smithy-checksums/src/lib.rs b/rust-runtime/aws-smithy-checksums/src/lib.rs index eef3a376a89..ce422fe5ee9 100644 --- a/rust-runtime/aws-smithy-checksums/src/lib.rs +++ b/rust-runtime/aws-smithy-checksums/src/lib.rs @@ -376,10 +376,14 @@ mod tests { } #[test] - #[should_panic = "called `Result::unwrap()` on an `Err` value: UnknownChecksumAlgorithmError { checksum_algorithm: \"some invalid checksum algorithm\" }"] fn test_checksum_algorithm_returns_error_for_unknown() { - "some invalid checksum algorithm" + let error = "some invalid checksum algorithm" .parse::() - .unwrap(); + .err() + .expect("it should error"); + assert_eq!( + "some invalid checksum algorithm", + error.checksum_algorithm() + ); } }