Skip to content

Commit

Permalink
Incorporate feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jdisanti committed Nov 11, 2022
1 parent 8572554 commit 104d2aa
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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<dyn #T + Send + Sync + 'static>", RuntimeType.StdError)
}
rustBlock("impl Unhandled") {
rustBlock("pub(crate) fn new(source: Box<dyn #T + Send + Sync + 'static>) -> Self", RuntimeType.StdError) {
rust("Self { source }")
rustTemplate(
"""
##[derive(Debug)]
pub struct Unhandled {
source: Box<dyn #{StdError} + Send + Sync + 'static>,
}
impl Unhandled {
pub(crate) fn new(source: Box<dyn #{StdError} + Send + Sync + 'static>) -> 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,
)
}
10 changes: 7 additions & 3 deletions rust-runtime/aws-smithy-checksums/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<ChecksumAlgorithm>()
.unwrap();
.err()
.expect("it should error");
assert_eq!(
"some invalid checksum algorithm",
error.checksum_algorithm()
);
}
}

0 comments on commit 104d2aa

Please sign in to comment.