Skip to content

Commit

Permalink
Revamp errors in aws-smithy-json (#1888)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdisanti authored Nov 15, 2022
1 parent fba88df commit 7b6d2d4
Show file tree
Hide file tree
Showing 12 changed files with 424 additions and 347 deletions.
4 changes: 2 additions & 2 deletions aws/rust-runtime/aws-config/src/json_credentials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ impl From<EscapeError> for InvalidJsonCredentials {
}
}

impl From<aws_smithy_json::deserialize::Error> for InvalidJsonCredentials {
fn from(err: aws_smithy_json::deserialize::Error) -> Self {
impl From<aws_smithy_json::deserialize::error::DeserializeError> for InvalidJsonCredentials {
fn from(err: aws_smithy_json::deserialize::error::DeserializeError) -> Self {
InvalidJsonCredentials::JsonError(err.into())
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ open class AwsJson(
"Bytes" to RuntimeType.Bytes,
"Error" to RuntimeType.GenericError(runtimeConfig),
"HeaderMap" to RuntimeType.http.member("HeaderMap"),
"JsonError" to CargoDependency.smithyJson(runtimeConfig).asType().member("deserialize::Error"),
"JsonError" to CargoDependency.smithyJson(runtimeConfig).asType().member("deserialize::error::DeserializeError"),
"Response" to RuntimeType.http.member("Response"),
"json_errors" to RuntimeType.jsonErrors(runtimeConfig),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ open class RestJson(val codegenContext: CodegenContext) : Protocol {
"Bytes" to RuntimeType.Bytes,
"Error" to RuntimeType.GenericError(runtimeConfig),
"HeaderMap" to RuntimeType.http.member("HeaderMap"),
"JsonError" to CargoDependency.smithyJson(runtimeConfig).asType().member("deserialize::Error"),
"JsonError" to CargoDependency.smithyJson(runtimeConfig).asType().member("deserialize::error::DeserializeError"),
"Response" to RuntimeType.http.member("Response"),
"json_errors" to RuntimeType.jsonErrors(runtimeConfig),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import software.amazon.smithy.model.traits.TimestampFormatTrait
import software.amazon.smithy.rust.codegen.core.rustlang.Attribute
import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency
import software.amazon.smithy.rust.codegen.core.rustlang.RustModule
import software.amazon.smithy.rust.codegen.core.rustlang.RustType
import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter
import software.amazon.smithy.rust.codegen.core.rustlang.Writable
import software.amazon.smithy.rust.codegen.core.rustlang.asType
Expand Down Expand Up @@ -100,8 +101,7 @@ class JsonParserGenerator(
private val jsonDeserModule = RustModule.private("json_deser")
private val typeConversionGenerator = TypeConversionGenerator(model, symbolProvider, runtimeConfig)
private val codegenScope = arrayOf(
"Error" to smithyJson.member("deserialize::Error"),
"ErrorReason" to smithyJson.member("deserialize::ErrorReason"),
"Error" to smithyJson.member("deserialize::error::DeserializeError"),
"expect_blob_or_null" to smithyJson.member("deserialize::token::expect_blob_or_null"),
"expect_bool_or_null" to smithyJson.member("deserialize::token::expect_bool_or_null"),
"expect_document" to smithyJson.member("deserialize::token::expect_document"),
Expand Down Expand Up @@ -422,7 +422,7 @@ class JsonParserGenerator(
*codegenScope,
) {
startObjectOrNull {
rust("let mut map = #T::new();", software.amazon.smithy.rust.codegen.core.rustlang.RustType.HashMap.RuntimeType)
rust("let mut map = #T::new();", RustType.HashMap.RuntimeType)
objectKeyLoop(hasMembers = true) {
withBlock("let key =", "?;") {
deserializeStringInner(keyTarget, "key")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1246,12 +1246,12 @@ private class ServerHttpBoundProtocolTraitImplGenerator(
if (model.expectShape(binding.member.target) is StringShape) {
return ServerRuntimeType.RequestRejection(runtimeConfig)
}
when (codegenContext.protocol) {
return when (codegenContext.protocol) {
RestJson1Trait.ID, AwsJson1_0Trait.ID, AwsJson1_1Trait.ID -> {
return CargoDependency.smithyJson(runtimeConfig).asType().member("deserialize").member("Error")
CargoDependency.smithyJson(runtimeConfig).asType().member("deserialize::error::DeserializeError")
}
RestXmlTrait.ID -> {
return CargoDependency.smithyXml(runtimeConfig).asType().member("decode").member("XmlError")
CargoDependency.smithyXml(runtimeConfig).asType().member("decode").member("XmlError")
}
else -> {
TODO("Protocol ${codegenContext.protocol} not supported yet")
Expand Down
2 changes: 1 addition & 1 deletion rust-runtime/aws-smithy-http-server/src/rejection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ impl From<MissingContentTypeReason> for RequestRejection {
// type. Generated functions that use [crate::rejection::RequestRejection] can thus use `?` to
// bubble up instead of having to sprinkle things like [`Result::map_err`] everywhere.

convert_to_request_rejection!(aws_smithy_json::deserialize::Error, JsonDeserialize);
convert_to_request_rejection!(aws_smithy_json::deserialize::error::DeserializeError, JsonDeserialize);
convert_to_request_rejection!(aws_smithy_xml::decode::XmlError, XmlDeserialize);
convert_to_request_rejection!(aws_smithy_http::header::ParseError, HeaderParse);
convert_to_request_rejection!(aws_smithy_types::date_time::DateTimeParseError, DateTimeParse);
Expand Down
Loading

0 comments on commit 7b6d2d4

Please sign in to comment.