From 07ba5119215338966917bb5bd316c6b7841c0d6c Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Mon, 14 Jul 2025 17:17:12 +0200 Subject: [PATCH] libutil: add a type-mapping TRY_AWAIT mapping the result of an await operation before unpacking it lets us inject rpc type conversion functions without duplicating all that is needed for proper exception wrapping and async error traces support. Change-Id: Ibcba1cc6d2b275757e3475881ef20f95dd4d684f --- lix/libutil/async.hh | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lix/libutil/async.hh b/lix/libutil/async.hh index 5dfd6e33c..e782001be 100644 --- a/lix/libutil/async.hh +++ b/lix/libutil/async.hh @@ -129,24 +129,27 @@ auto runAsyncInNewThread(std::invocable auto fn) return AIOROOT.blockOn(__VA_ARGS__); \ }) -#define LIX_TRY_AWAIT_CONTEXT(ctx, ...) \ +#define LIX_TRY_AWAIT_CONTEXT_MAP(_l_ctx, _l_map, ...) \ ({ \ - auto _lix_awaited = co_await (__VA_ARGS__); \ + auto _lix_awaited = (_l_map) (co_await (__VA_ARGS__)); \ if (_lix_awaited.has_error()) { \ try { \ _lix_awaited.value(); \ } catch (::nix::BaseException & e) { \ - e.addAsyncTrace(::std::source_location::current(), ctx()); \ + e.addAsyncTrace(::std::source_location::current(), _l_ctx()); \ throw; \ } catch (::std::exception & e) { /* NOLINT(lix-foreign-exceptions) */ \ ::nix::ForeignException fe(e); \ - fe.addAsyncTrace(::std::source_location::current(), ctx()); \ + fe.addAsyncTrace(::std::source_location::current(), _l_ctx()); \ throw fe; \ } \ } \ ::nix::detail::materializeResult(std::move(_lix_awaited)); \ }) +#define LIX_TRY_AWAIT_CONTEXT(_l_ctx, ...) \ + LIX_TRY_AWAIT_CONTEXT_MAP(_l_ctx, (std::identity{}), __VA_ARGS__) + /** * Magic name used by `LIX_TRY_AWAIT` to insert additional context into an * async trace frame. This name will be looked up in the local scope every