Skip to content

Commit 302fabd

Browse files
authored
fix(executor): Add missing try/catch (alibaba#54)
1 parent b1ffd6f commit 302fabd

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

src/paimon/common/executor/default_executor_test.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,10 @@ TEST(DefaultExecutorTest, TestViaWithResult) {
7474
ASSERT_EQ(4, results.size());
7575
}
7676

77+
TEST(DefaultExecutorTest, TestViaWithException) {
78+
auto executor = GetGlobalDefaultExecutor();
79+
auto future = Via(executor.get(), []() { throw std::runtime_error("test"); });
80+
ASSERT_THROW(future.get(), std::runtime_error);
81+
}
82+
7783
} // namespace paimon::test

src/paimon/common/executor/future.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,15 @@ auto Via(Executor* executor, Func&& func) -> std::future<decltype(func())> {
6666

6767
// Wrap the task and submit it to the executor.
6868
executor->Add([promise, func = std::forward<Func>(func)]() mutable {
69-
if constexpr (std::is_void_v<ResultType>) {
70-
func();
71-
promise->set_value();
72-
} else {
73-
promise->set_value(func());
69+
try {
70+
if constexpr (std::is_void_v<ResultType>) {
71+
func();
72+
promise->set_value();
73+
} else {
74+
promise->set_value(func());
75+
}
76+
} catch (...) {
77+
promise->set_exception(std::current_exception());
7478
}
7579
});
7680

0 commit comments

Comments
 (0)