|
29 | 29 | #include "common/async/blocked_completion.h" |
30 | 30 | #include "common/async/concepts.h" |
31 | 31 | #include "common/async/yield_context.h" |
| 32 | +#include "common/async/redirect_error.h" |
32 | 33 |
|
33 | 34 | #include "common/dout.h" |
34 | 35 | #include "common/dout_fmt.h" |
@@ -60,13 +61,10 @@ inline int run_coro( |
60 | 61 | std::string* what ///< Where to store the result of `what()` on exception |
61 | 62 | ) noexcept |
62 | 63 | { |
63 | | - try { |
64 | | - maybe_warn_about_blocking(dpp); |
65 | | - asio::co_spawn(executor, std::move(coro), async::use_blocked); |
66 | | - } catch (const std::exception&) { |
67 | | - return ceph::from_exception(std::current_exception(), what); |
68 | | - } |
69 | | - return 0; |
| 64 | + std::exception_ptr e; |
| 65 | + maybe_warn_about_blocking(dpp); |
| 66 | + asio::co_spawn(executor, std::move(coro), async::use_blocked[e]); |
| 67 | + return ceph::from_exception(e, what); |
70 | 68 | } |
71 | 69 |
|
72 | 70 | /// Call a coroutine and block until it completes, handling exceptions |
@@ -107,13 +105,10 @@ int run_coro( |
107 | 105 | std::string* what ///< Where to store the result of `what()`. |
108 | 106 | ) noexcept |
109 | 107 | { |
110 | | - try { |
111 | | - val = asio::co_spawn(executor, std::move(coro), async::use_blocked); |
112 | | - maybe_warn_about_blocking(dpp); |
113 | | - } catch (const std::exception& e) { |
114 | | - return ceph::from_exception(std::current_exception(), what); |
115 | | - } |
116 | | - return 0; |
| 108 | + std::exception_ptr e; |
| 109 | + maybe_warn_about_blocking(dpp); |
| 110 | + val = asio::co_spawn(executor, std::move(coro), async::use_blocked[e]); |
| 111 | + return ceph::from_exception(e, what); |
117 | 112 | } |
118 | 113 |
|
119 | 114 | /// Call a coroutine and block until it completes, handling exceptions |
@@ -156,13 +151,10 @@ int run_coro( |
156 | 151 | std::string* what ///< Where to store the result of `what()`. |
157 | 152 | ) noexcept |
158 | 153 | { |
159 | | - try { |
160 | | - maybe_warn_about_blocking(dpp); |
161 | | - vals = asio::co_spawn(executor, std::move(coro), async::use_blocked); |
162 | | - } catch (const std::exception& e) { |
163 | | - return ceph::from_exception(std::current_exception(), what); |
164 | | - } |
165 | | - return 0; |
| 154 | + std::exception_ptr e; |
| 155 | + maybe_warn_about_blocking(dpp); |
| 156 | + vals = asio::co_spawn(executor, std::move(coro), async::use_blocked[e]); |
| 157 | + return ceph::from_exception(e, what); |
166 | 158 | } |
167 | 159 |
|
168 | 160 | /// Call a coroutine and block until it completes, handling exceptions |
@@ -203,19 +195,21 @@ int run_coro( |
203 | 195 | int log_level = 5 /// What level to log at |
204 | 196 | ) noexcept |
205 | 197 | { |
206 | | - try { |
207 | | - if (y) { |
208 | | - auto& yield = y.get_yield_context(); |
209 | | - asio::co_spawn(yield.get_executor(), std::move(coro), yield); |
210 | | - } else { |
211 | | - maybe_warn_about_blocking(dpp); |
212 | | - asio::co_spawn(executor, std::move(coro), async::use_blocked); |
213 | | - } |
214 | | - } catch (const std::exception& e) { |
215 | | - ldpp_dout_fmt(dpp, log_level, "{}: failed: {}", name, e.what()); |
216 | | - return ceph::from_exception(std::current_exception()); |
| 198 | + std::exception_ptr e; |
| 199 | + if (y) { |
| 200 | + auto& yield = y.get_yield_context(); |
| 201 | + asio::co_spawn(yield.get_executor(), std::move(coro), |
| 202 | + async::redirect_error(yield, e)); |
| 203 | + } else { |
| 204 | + maybe_warn_about_blocking(dpp); |
| 205 | + asio::co_spawn(executor, std::move(coro), async::use_blocked[e]); |
217 | 206 | } |
218 | | - return 0; |
| 207 | + std::string what; |
| 208 | + auto r = ceph::from_exception(e, &what); |
| 209 | + if (e) [[unlikely]] { |
| 210 | + ldpp_dout_fmt(dpp, log_level, "{}: failed: {}", name, what); |
| 211 | + } |
| 212 | + return r; |
219 | 213 | } |
220 | 214 |
|
221 | 215 | /// Call a coroutine and block until it completes, handling exceptions |
@@ -260,20 +254,21 @@ int run_coro( |
260 | 254 | int log_level = 5 /// What level to log at |
261 | 255 | ) noexcept |
262 | 256 | { |
263 | | - try { |
264 | | - if (y) { |
265 | | - auto& yield = y.get_yield_context(); |
266 | | - val = asio::co_spawn(yield.get_executor(), std::move(coro), yield); |
267 | | - } else { |
268 | | - maybe_warn_about_blocking(dpp); |
269 | | - val = asio::co_spawn(executor, std::move(coro), async::use_blocked); |
270 | | - } |
271 | | - } catch (const std::exception& e) { |
272 | | - ldpp_dout_fmt(dpp, log_level, "{}: failed: {}", name, e.what()); |
273 | | - return ceph::from_exception(std::current_exception()); |
| 257 | + std::exception_ptr e; |
| 258 | + if (y) { |
| 259 | + auto& yield = y.get_yield_context(); |
| 260 | + val = asio::co_spawn(yield.get_executor(), std::move(coro), |
| 261 | + async::redirect_error(yield, e)); |
| 262 | + } else { |
| 263 | + maybe_warn_about_blocking(dpp); |
| 264 | + val = asio::co_spawn(executor, std::move(coro), async::use_blocked[e]); |
274 | 265 | } |
275 | | - |
276 | | - return 0; |
| 266 | + std::string what; |
| 267 | + auto r = ceph::from_exception(e, &what); |
| 268 | + if (e) [[unlikely]] { |
| 269 | + ldpp_dout_fmt(dpp, log_level, "{}: failed: {}", name, what); |
| 270 | + } |
| 271 | + return r; |
277 | 272 | } |
278 | 273 |
|
279 | 274 | /// Call a coroutine and block until it completes, handling exceptions |
@@ -317,19 +312,21 @@ int run_coro( |
317 | 312 | int log_level = 5 /// What level to log at |
318 | 313 | ) noexcept |
319 | 314 | { |
320 | | - try { |
321 | | - if (y) { |
322 | | - auto& yield = y.get_yield_context(); |
323 | | - vals = asio::co_spawn(yield.get_executor(), std::move(coro), yield); |
324 | | - } else { |
325 | | - maybe_warn_about_blocking(dpp); |
326 | | - vals = asio::co_spawn(executor, std::move(coro), async::use_blocked); |
327 | | - } |
328 | | - } catch (const std::exception& e) { |
329 | | - ldpp_dout_fmt(dpp, log_level, "{}: failed: {}", name, e.what()); |
330 | | - return ceph::from_exception(std::current_exception()); |
| 315 | + std::exception_ptr e; |
| 316 | + if (y) { |
| 317 | + auto& yield = y.get_yield_context(); |
| 318 | + vals = asio::co_spawn(yield.get_executor(), std::move(coro), |
| 319 | + async::redirect_error(yield, e)); |
| 320 | + } else { |
| 321 | + maybe_warn_about_blocking(dpp); |
| 322 | + vals = asio::co_spawn(executor, std::move(coro), async::use_blocked[e]); |
| 323 | + } |
| 324 | + std::string what; |
| 325 | + auto r = ceph::from_exception(e, &what); |
| 326 | + if (e) [[unlikely]] { |
| 327 | + ldpp_dout_fmt(dpp, log_level, "{}: failed: {}", name, what); |
331 | 328 | } |
332 | | - return 0; |
| 329 | + return r; |
333 | 330 | } |
334 | 331 |
|
335 | 332 | /// Call a coroutine and block until it completes, handling exceptions |
|
0 commit comments