Commit f1d6c61c authored by Lee Howes's avatar Lee Howes Committed by Facebook Github Bot

Ensure that remaining thenError case takes an r-value exception and fix tests to check for it

Summary:
Fixes a missed r-value parameter case for exceptions passed to thenError continuations.

Adds tests to separate l-value for onError from r-value from thenError.

Reviewed By: yfeldblum

Differential Revision: D13928271

fbshipit-source-id: 0a720730d32c158fb82b61dccd0426b1fe55169f
parent 0c267afc
......@@ -1125,7 +1125,7 @@ Future<T>::thenError(tag_t<ExceptionType>, F&& func) && {
std::move(p), std::forward<F>(func))](Try<T>&& t) mutable {
if (auto ex = t.template tryGetExceptionObject<
std::remove_reference_t<ExceptionType>>()) {
auto tf2 = state.tryInvoke(*ex);
auto tf2 = state.tryInvoke(std::move(*ex));
if (tf2.hasException()) {
state.setException(std::move(tf2.exception()));
} else {
......
......@@ -328,13 +328,22 @@ TEST(Future, hasPostconditionInvalid) {
}
namespace {
Future<int> onErrorHelperEggs(const eggs_t&) {
Future<int> onErrorHelperEggs(eggs_t&) {
return makeFuture(10);
}
Future<int> onErrorHelperGeneric(const std::exception&) {
Future<int> onErrorHelperGeneric(std::exception&) {
return makeFuture(20);
}
Future<int> onErrorHelperWrapper(folly::exception_wrapper&&) {
Future<int> onErrorHelperWrapper(folly::exception_wrapper&) {
return makeFuture(30);
}
Future<int> thenErrorHelperEggs(eggs_t&&) {
return makeFuture(10);
}
Future<int> thenErrorHelperGeneric(std::exception&&) {
return makeFuture(20);
}
Future<int> thenErrorHelperWrapper(folly::exception_wrapper&&) {
return makeFuture(30);
}
} // namespace
......@@ -480,23 +489,23 @@ TEST(Future, onError) {
{
auto f = makeFuture()
.thenValue([](auto &&) -> int { throw eggs; })
.thenError(tag_t<eggs_t>{}, onErrorHelperEggs)
.thenError<std::exception>(onErrorHelperGeneric);
.thenError(tag_t<eggs_t>{}, thenErrorHelperEggs)
.thenError<std::exception>(thenErrorHelperGeneric);
EXPECT_EQ(10, f.value());
}
{
auto f =
makeFuture()
.thenValue([](auto &&) -> int { throw std::runtime_error("test"); })
.thenError(tag_t<eggs_t>{}, onErrorHelperEggs)
.thenError(onErrorHelperWrapper);
.thenError(tag_t<eggs_t>{}, thenErrorHelperEggs)
.thenError(thenErrorHelperWrapper);
EXPECT_EQ(30, f.value());
}
{
auto f =
makeFuture()
.thenValue([](auto &&) -> int { throw std::runtime_error("test"); })
.thenError(tag_t<eggs_t>{}, onErrorHelperEggs);
.thenError(tag_t<eggs_t>{}, thenErrorHelperEggs);
EXPECT_THROW(f.value(), std::runtime_error);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment