Skip to content

Commit

Permalink
Use folly::Try to capture exceptions thrown in ClientInterceptor
Browse files Browse the repository at this point in the history
Summary: This avoid code generation bloat from `try` / `catch` in generated code.

Reviewed By: sazonovkirill

Differential Revision: D62435321

fbshipit-source-id: 245dbb89ed02f239e804c1fc67976d23e0dd7bb0
  • Loading branch information
praihan authored and facebook-github-bot committed Sep 12, 2024
1 parent 34960bd commit d317850
Show file tree
Hide file tree
Showing 112 changed files with 1,401 additions and 1,397 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ void {{ > service_common/client_class_name}}::sync_{{function:cpp_name}}(apache:
{{/function:creates_interaction?}}
auto* contextStack = ctxAndHeader.first.get();
if (contextStack != nullptr) {
contextStack->processClientInterceptorsOnRequest();
contextStack->processClientInterceptorsOnRequest().throwUnlessValue();
}
callback.waitUntilDone(
evb,
[&] {
fbthrift_serialize_and_send_{{function:cpp_name}}(rpcOptions, std::move(ctxAndHeader.second), ctxAndHeader.first.get(), std::move(wrappedCallback){{#function:creates_interaction?}}, handle{{/function:creates_interaction?}}{{function:comma}}{{ > service_common/param_list}});
});
if (contextStack != nullptr) {
contextStack->processClientInterceptorsOnResponse();
contextStack->processClientInterceptorsOnResponse().throwUnlessValue();
}
if (returnState.isException()) {
returnState.exception().throw_exception();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
{{function:created_interaction}} handle(channel_, "{{function:created_interaction}}");
{{/function:creates_interaction?}}
if (ctx != nullptr) {
ctx->processClientInterceptorsOnRequest();
ctx->processClientInterceptorsOnRequest().throwUnlessValue();
}
if constexpr (hasRpcOptions) {
fbthrift_serialize_and_send_{{function:cpp_name}}(*rpcOptions, std::move(header), ctx.get(), std::move(wrappedCallback){{#function:creates_interaction?}}, handle{{/function:creates_interaction?}}{{function:comma}}{{ > service_common/param_list}});
Expand All @@ -153,7 +153,7 @@
co_await callback.co_waitUntilDone();
}
if (ctx != nullptr) {
ctx->processClientInterceptorsOnResponse();
ctx->processClientInterceptorsOnResponse().throwUnlessValue();
}
if (returnState.isException()) {
co_yield folly::coro::co_error(std::move(returnState.exception()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@ void apache::thrift::Client<::facebook::thrift::test::AdapterService>::sync_coun
auto wrappedCallback = apache::thrift::RequestClientCallback::Ptr(&callback);
auto* contextStack = ctxAndHeader.first.get();
if (contextStack != nullptr) {
contextStack->processClientInterceptorsOnRequest();
contextStack->processClientInterceptorsOnRequest().throwUnlessValue();
}
callback.waitUntilDone(
evb,
[&] {
fbthrift_serialize_and_send_count(rpcOptions, std::move(ctxAndHeader.second), ctxAndHeader.first.get(), std::move(wrappedCallback));
});
if (contextStack != nullptr) {
contextStack->processClientInterceptorsOnResponse();
contextStack->processClientInterceptorsOnResponse().throwUnlessValue();
}
if (returnState.isException()) {
returnState.exception().throw_exception();
Expand Down Expand Up @@ -294,15 +294,15 @@ void apache::thrift::Client<::facebook::thrift::test::AdapterService>::sync_adap
auto wrappedCallback = apache::thrift::RequestClientCallback::Ptr(&callback);
auto* contextStack = ctxAndHeader.first.get();
if (contextStack != nullptr) {
contextStack->processClientInterceptorsOnRequest();
contextStack->processClientInterceptorsOnRequest().throwUnlessValue();
}
callback.waitUntilDone(
evb,
[&] {
fbthrift_serialize_and_send_adaptedTypes(rpcOptions, std::move(ctxAndHeader.second), ctxAndHeader.first.get(), std::move(wrappedCallback), p_arg);
});
if (contextStack != nullptr) {
contextStack->processClientInterceptorsOnResponse();
contextStack->processClientInterceptorsOnResponse().throwUnlessValue();
}
if (returnState.isException()) {
returnState.exception().throw_exception();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class Client<::facebook::thrift::test::AdapterService> : public apache::thrift::
static apache::thrift::RpcOptions* defaultRpcOptions = new apache::thrift::RpcOptions();
auto wrappedCallback = apache::thrift::RequestClientCallback::Ptr(cancellableCallback ? (apache::thrift::RequestClientCallback*)cancellableCallback.get() : &callback);
if (ctx != nullptr) {
ctx->processClientInterceptorsOnRequest();
ctx->processClientInterceptorsOnRequest().throwUnlessValue();
}
if constexpr (hasRpcOptions) {
fbthrift_serialize_and_send_count(*rpcOptions, std::move(header), ctx.get(), std::move(wrappedCallback));
Expand All @@ -108,7 +108,7 @@ class Client<::facebook::thrift::test::AdapterService> : public apache::thrift::
co_await callback.co_waitUntilDone();
}
if (ctx != nullptr) {
ctx->processClientInterceptorsOnResponse();
ctx->processClientInterceptorsOnResponse().throwUnlessValue();
}
if (returnState.isException()) {
co_yield folly::coro::co_error(std::move(returnState.exception()));
Expand Down Expand Up @@ -213,7 +213,7 @@ class Client<::facebook::thrift::test::AdapterService> : public apache::thrift::
static apache::thrift::RpcOptions* defaultRpcOptions = new apache::thrift::RpcOptions();
auto wrappedCallback = apache::thrift::RequestClientCallback::Ptr(cancellableCallback ? (apache::thrift::RequestClientCallback*)cancellableCallback.get() : &callback);
if (ctx != nullptr) {
ctx->processClientInterceptorsOnRequest();
ctx->processClientInterceptorsOnRequest().throwUnlessValue();
}
if constexpr (hasRpcOptions) {
fbthrift_serialize_and_send_adaptedTypes(*rpcOptions, std::move(header), ctx.get(), std::move(wrappedCallback), p_arg);
Expand All @@ -227,7 +227,7 @@ class Client<::facebook::thrift::test::AdapterService> : public apache::thrift::
co_await callback.co_waitUntilDone();
}
if (ctx != nullptr) {
ctx->processClientInterceptorsOnResponse();
ctx->processClientInterceptorsOnResponse().throwUnlessValue();
}
if (returnState.isException()) {
co_yield folly::coro::co_error(std::move(returnState.exception()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ ::facebook::thrift::test::MyI32_4873 apache::thrift::Client<::facebook::thrift::
auto wrappedCallback = apache::thrift::RequestClientCallback::Ptr(&callback);
auto* contextStack = ctxAndHeader.first.get();
if (contextStack != nullptr) {
contextStack->processClientInterceptorsOnRequest();
contextStack->processClientInterceptorsOnRequest().throwUnlessValue();
}
callback.waitUntilDone(
evb,
[&] {
fbthrift_serialize_and_send_func(rpcOptions, std::move(ctxAndHeader.second), ctxAndHeader.first.get(), std::move(wrappedCallback), p_arg1, p_arg2, p_arg3);
});
if (contextStack != nullptr) {
contextStack->processClientInterceptorsOnResponse();
contextStack->processClientInterceptorsOnResponse().throwUnlessValue();
}
if (returnState.isException()) {
returnState.exception().throw_exception();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class Client<::facebook::thrift::test::Service> : public apache::thrift::Generat
static apache::thrift::RpcOptions* defaultRpcOptions = new apache::thrift::RpcOptions();
auto wrappedCallback = apache::thrift::RequestClientCallback::Ptr(cancellableCallback ? (apache::thrift::RequestClientCallback*)cancellableCallback.get() : &callback);
if (ctx != nullptr) {
ctx->processClientInterceptorsOnRequest();
ctx->processClientInterceptorsOnRequest().throwUnlessValue();
}
if constexpr (hasRpcOptions) {
fbthrift_serialize_and_send_func(*rpcOptions, std::move(header), ctx.get(), std::move(wrappedCallback), p_arg1, p_arg2, p_arg3);
Expand All @@ -108,7 +108,7 @@ class Client<::facebook::thrift::test::Service> : public apache::thrift::Generat
co_await callback.co_waitUntilDone();
}
if (ctx != nullptr) {
ctx->processClientInterceptorsOnResponse();
ctx->processClientInterceptorsOnResponse().throwUnlessValue();
}
if (returnState.isException()) {
co_yield folly::coro::co_error(std::move(returnState.exception()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ ::std::int32_t apache::thrift::Client<::cpp2::GoodService>::sync_bar(apache::thr
auto wrappedCallback = apache::thrift::RequestClientCallback::Ptr(&callback);
auto* contextStack = ctxAndHeader.first.get();
if (contextStack != nullptr) {
contextStack->processClientInterceptorsOnRequest();
contextStack->processClientInterceptorsOnRequest().throwUnlessValue();
}
callback.waitUntilDone(
evb,
[&] {
fbthrift_serialize_and_send_bar(rpcOptions, std::move(ctxAndHeader.second), ctxAndHeader.first.get(), std::move(wrappedCallback));
});
if (contextStack != nullptr) {
contextStack->processClientInterceptorsOnResponse();
contextStack->processClientInterceptorsOnResponse().throwUnlessValue();
}
if (returnState.isException()) {
returnState.exception().throw_exception();
Expand Down Expand Up @@ -302,15 +302,15 @@ void apache::thrift::Client<::cpp2::GoodService>::BadInteraction::sync_foo(apach
auto wrappedCallback = apache::thrift::RequestClientCallback::Ptr(&callback);
auto* contextStack = ctxAndHeader.first.get();
if (contextStack != nullptr) {
contextStack->processClientInterceptorsOnRequest();
contextStack->processClientInterceptorsOnRequest().throwUnlessValue();
}
callback.waitUntilDone(
evb,
[&] {
fbthrift_serialize_and_send_foo(rpcOptions, std::move(ctxAndHeader.second), ctxAndHeader.first.get(), std::move(wrappedCallback));
});
if (contextStack != nullptr) {
contextStack->processClientInterceptorsOnResponse();
contextStack->processClientInterceptorsOnResponse().throwUnlessValue();
}
if (returnState.isException()) {
returnState.exception().throw_exception();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class BadInteraction final : public apache::thrift::InteractionHandle {
static apache::thrift::RpcOptions* defaultRpcOptions = new apache::thrift::RpcOptions();
auto wrappedCallback = apache::thrift::RequestClientCallback::Ptr(cancellableCallback ? (apache::thrift::RequestClientCallback*)cancellableCallback.get() : &callback);
if (ctx != nullptr) {
ctx->processClientInterceptorsOnRequest();
ctx->processClientInterceptorsOnRequest().throwUnlessValue();
}
if constexpr (hasRpcOptions) {
fbthrift_serialize_and_send_foo(*rpcOptions, std::move(header), ctx.get(), std::move(wrappedCallback));
Expand All @@ -111,7 +111,7 @@ class BadInteraction final : public apache::thrift::InteractionHandle {
co_await callback.co_waitUntilDone();
}
if (ctx != nullptr) {
ctx->processClientInterceptorsOnResponse();
ctx->processClientInterceptorsOnResponse().throwUnlessValue();
}
if (returnState.isException()) {
co_yield folly::coro::co_error(std::move(returnState.exception()));
Expand Down Expand Up @@ -209,7 +209,7 @@ class BadInteraction final : public apache::thrift::InteractionHandle {
static apache::thrift::RpcOptions* defaultRpcOptions = new apache::thrift::RpcOptions();
auto wrappedCallback = apache::thrift::RequestClientCallback::Ptr(cancellableCallback ? (apache::thrift::RequestClientCallback*)cancellableCallback.get() : &callback);
if (ctx != nullptr) {
ctx->processClientInterceptorsOnRequest();
ctx->processClientInterceptorsOnRequest().throwUnlessValue();
}
if constexpr (hasRpcOptions) {
fbthrift_serialize_and_send_bar(*rpcOptions, std::move(header), ctx.get(), std::move(wrappedCallback));
Expand All @@ -223,7 +223,7 @@ class BadInteraction final : public apache::thrift::InteractionHandle {
co_await callback.co_waitUntilDone();
}
if (ctx != nullptr) {
ctx->processClientInterceptorsOnResponse();
ctx->processClientInterceptorsOnResponse().throwUnlessValue();
}
if (returnState.isException()) {
co_yield folly::coro::co_error(std::move(returnState.exception()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ void apache::thrift::Client<::cpp2::FooBarBazService>::sync_foo(apache::thrift::
auto wrappedCallback = apache::thrift::RequestClientCallback::Ptr(&callback);
auto* contextStack = ctxAndHeader.first.get();
if (contextStack != nullptr) {
contextStack->processClientInterceptorsOnRequest();
contextStack->processClientInterceptorsOnRequest().throwUnlessValue();
}
callback.waitUntilDone(
evb,
[&] {
fbthrift_serialize_and_send_foo(rpcOptions, std::move(ctxAndHeader.second), ctxAndHeader.first.get(), std::move(wrappedCallback));
});
if (contextStack != nullptr) {
contextStack->processClientInterceptorsOnResponse();
contextStack->processClientInterceptorsOnResponse().throwUnlessValue();
}
if (returnState.isException()) {
returnState.exception().throw_exception();
Expand Down Expand Up @@ -306,15 +306,15 @@ void apache::thrift::Client<::cpp2::FooBarBazService>::sync_bar(apache::thrift::
auto wrappedCallback = apache::thrift::RequestClientCallback::Ptr(&callback);
auto* contextStack = ctxAndHeader.first.get();
if (contextStack != nullptr) {
contextStack->processClientInterceptorsOnRequest();
contextStack->processClientInterceptorsOnRequest().throwUnlessValue();
}
callback.waitUntilDone(
evb,
[&] {
fbthrift_serialize_and_send_bar(rpcOptions, std::move(ctxAndHeader.second), ctxAndHeader.first.get(), std::move(wrappedCallback));
});
if (contextStack != nullptr) {
contextStack->processClientInterceptorsOnResponse();
contextStack->processClientInterceptorsOnResponse().throwUnlessValue();
}
if (returnState.isException()) {
returnState.exception().throw_exception();
Expand Down Expand Up @@ -490,15 +490,15 @@ void apache::thrift::Client<::cpp2::FooBarBazService>::sync_baz(apache::thrift::
auto wrappedCallback = apache::thrift::RequestClientCallback::Ptr(&callback);
auto* contextStack = ctxAndHeader.first.get();
if (contextStack != nullptr) {
contextStack->processClientInterceptorsOnRequest();
contextStack->processClientInterceptorsOnRequest().throwUnlessValue();
}
callback.waitUntilDone(
evb,
[&] {
fbthrift_serialize_and_send_baz(rpcOptions, std::move(ctxAndHeader.second), ctxAndHeader.first.get(), std::move(wrappedCallback));
});
if (contextStack != nullptr) {
contextStack->processClientInterceptorsOnResponse();
contextStack->processClientInterceptorsOnResponse().throwUnlessValue();
}
if (returnState.isException()) {
returnState.exception().throw_exception();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class Client<::cpp2::FooBarBazService> : public apache::thrift::GeneratedAsyncCl
static apache::thrift::RpcOptions* defaultRpcOptions = new apache::thrift::RpcOptions();
auto wrappedCallback = apache::thrift::RequestClientCallback::Ptr(cancellableCallback ? (apache::thrift::RequestClientCallback*)cancellableCallback.get() : &callback);
if (ctx != nullptr) {
ctx->processClientInterceptorsOnRequest();
ctx->processClientInterceptorsOnRequest().throwUnlessValue();
}
if constexpr (hasRpcOptions) {
fbthrift_serialize_and_send_foo(*rpcOptions, std::move(header), ctx.get(), std::move(wrappedCallback));
Expand All @@ -104,7 +104,7 @@ class Client<::cpp2::FooBarBazService> : public apache::thrift::GeneratedAsyncCl
co_await callback.co_waitUntilDone();
}
if (ctx != nullptr) {
ctx->processClientInterceptorsOnResponse();
ctx->processClientInterceptorsOnResponse().throwUnlessValue();
}
if (returnState.isException()) {
co_yield folly::coro::co_error(std::move(returnState.exception()));
Expand Down Expand Up @@ -207,7 +207,7 @@ class Client<::cpp2::FooBarBazService> : public apache::thrift::GeneratedAsyncCl
static apache::thrift::RpcOptions* defaultRpcOptions = new apache::thrift::RpcOptions();
auto wrappedCallback = apache::thrift::RequestClientCallback::Ptr(cancellableCallback ? (apache::thrift::RequestClientCallback*)cancellableCallback.get() : &callback);
if (ctx != nullptr) {
ctx->processClientInterceptorsOnRequest();
ctx->processClientInterceptorsOnRequest().throwUnlessValue();
}
if constexpr (hasRpcOptions) {
fbthrift_serialize_and_send_bar(*rpcOptions, std::move(header), ctx.get(), std::move(wrappedCallback));
Expand All @@ -221,7 +221,7 @@ class Client<::cpp2::FooBarBazService> : public apache::thrift::GeneratedAsyncCl
co_await callback.co_waitUntilDone();
}
if (ctx != nullptr) {
ctx->processClientInterceptorsOnResponse();
ctx->processClientInterceptorsOnResponse().throwUnlessValue();
}
if (returnState.isException()) {
co_yield folly::coro::co_error(std::move(returnState.exception()));
Expand Down Expand Up @@ -324,7 +324,7 @@ class Client<::cpp2::FooBarBazService> : public apache::thrift::GeneratedAsyncCl
static apache::thrift::RpcOptions* defaultRpcOptions = new apache::thrift::RpcOptions();
auto wrappedCallback = apache::thrift::RequestClientCallback::Ptr(cancellableCallback ? (apache::thrift::RequestClientCallback*)cancellableCallback.get() : &callback);
if (ctx != nullptr) {
ctx->processClientInterceptorsOnRequest();
ctx->processClientInterceptorsOnRequest().throwUnlessValue();
}
if constexpr (hasRpcOptions) {
fbthrift_serialize_and_send_baz(*rpcOptions, std::move(header), ctx.get(), std::move(wrappedCallback));
Expand All @@ -338,7 +338,7 @@ class Client<::cpp2::FooBarBazService> : public apache::thrift::GeneratedAsyncCl
co_await callback.co_waitUntilDone();
}
if (ctx != nullptr) {
ctx->processClientInterceptorsOnResponse();
ctx->processClientInterceptorsOnResponse().throwUnlessValue();
}
if (returnState.isException()) {
co_yield folly::coro::co_error(std::move(returnState.exception()));
Expand Down
Loading

0 comments on commit d317850

Please sign in to comment.