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

Revamp errors in aws-smithy-json #1888

Merged
merged 5 commits into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
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)
Velfi marked this conversation as resolved.
Show resolved Hide resolved
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