Skip to content

Commit

Permalink
Wrap calls to async constructors in synchronous code with Task.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sichan Yoo committed Jan 30, 2024
1 parent 304a68a commit 461e2ef
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,13 @@ class MessageUnmarshallableGenerator(val ctx: ProtocolGenerator.GenerationContex
writer.write("default:")
writer.indent {
writer.write("let httpResponse = HttpResponse(body: .data(message.payload), statusCode: .ok)")
writer.write(
"return \$L(httpResponse: httpResponse, message: \"error processing event stream, unrecognized ':exceptionType': \\(params.exceptionType); contentType: \\(params.contentType ?? \"nil\")\", requestID: nil, typeName: nil)",
AWSClientRuntimeTypes.Core.UnknownAWSHTTPServiceError
)
writer.openBlock("Task {", "}") {
writer.write(
"let errorToReturn = await \$L(httpResponse: httpResponse, message: \"error processing event stream, unrecognized ':exceptionType': \\(params.exceptionType); contentType: \\(params.contentType ?? \"nil\")\", requestID: nil, typeName: nil)",
AWSClientRuntimeTypes.Core.UnknownAWSHTTPServiceError
)
writer.write("return errorToReturn")
}
}
writer.write("}")
}
Expand All @@ -98,10 +101,13 @@ class MessageUnmarshallableGenerator(val ctx: ProtocolGenerator.GenerationContex
writer.indent {
// this is a service exception still, just un-modeled
writer.write("let httpResponse = HttpResponse(body: .data(message.payload), statusCode: .ok)")
writer.write(
"throw \$L(httpResponse: httpResponse, message: \"error processing event stream, unrecognized ':errorType': \\(params.errorCode); message: \\(params.message ?? \"nil\")\", requestID: nil, typeName: nil)",
AWSClientRuntimeTypes.Core.UnknownAWSHTTPServiceError
)
writer.openBlock("Task {", "}") {
writer.write(
"let errorToThrow = await \$L(httpResponse: httpResponse, message: \"error processing event stream, unrecognized ':errorType': \\(params.errorCode); message: \\(params.message ?? \"nil\")\", requestID: nil, typeName: nil)",
AWSClientRuntimeTypes.Core.UnknownAWSHTTPServiceError
)
writer.write("throw errorToThrow")
}
}
writer.write("case .unknown(messageType: let messageType):")
writer.indent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,20 @@ extension EventStreamTestClientTypes.TestStream: ClientRuntime.MessageUnmarshall
return try decoder.decode(responseBody: message.payload) as SomeError
default:
let httpResponse = HttpResponse(body: .data(message.payload), statusCode: .ok)
return AWSClientRuntime.UnknownAWSHTTPServiceError(httpResponse: httpResponse, message: "error processing event stream, unrecognized ':exceptionType': \(params.exceptionType); contentType: \(params.contentType ?? "nil")", requestID: nil, typeName: nil)
Task {
let errorToReturn = await AWSClientRuntime.UnknownAWSHTTPServiceError(httpResponse: httpResponse, message: "error processing event stream, unrecognized ':exceptionType': \(params.exceptionType); contentType: \(params.contentType ?? "nil")", requestID: nil, typeName: nil)
return errorToReturn
}
}
}
let error = try makeError(message, params)
throw error
case .error(let params):
let httpResponse = HttpResponse(body: .data(message.payload), statusCode: .ok)
throw AWSClientRuntime.UnknownAWSHTTPServiceError(httpResponse: httpResponse, message: "error processing event stream, unrecognized ':errorType': \(params.errorCode); message: \(params.message ?? "nil")", requestID: nil, typeName: nil)
Task {
let errorToThrow = await AWSClientRuntime.UnknownAWSHTTPServiceError(httpResponse: httpResponse, message: "error processing event stream, unrecognized ':errorType': \(params.errorCode); message: \(params.message ?? "nil")", requestID: nil, typeName: nil)
throw errorToThrow
}
case .unknown(messageType: let messageType):
throw ClientRuntime.ClientError.unknownError("unrecognized event stream message ':message-type': \(messageType)")
}
Expand Down

0 comments on commit 461e2ef

Please sign in to comment.