29template<
int ErrnoValue,
auto ErrorCode =
DFX_ERROR,
auto SuccessCode =
DFX_OK,
typename F,
typename ... Args>
30requires std::invocable<F, Args...>
31auto safeInvokeFFI(std::shared_ptr<spdlog::logger> logger, F && f, Args && ... args)
noexcept
35 std::invoke(std::forward<F>(f), std::forward<Args>(args)...);
40 if (logger !=
nullptr)
43 catch (std::exception
const & e)
45 DFX_LLOG(logger, spdlog::level::err,
"An error occurred: {}", e.what());
49 DFX_LLOG(logger, spdlog::level::err,
"An unknown error occurred");
52 if constexpr (ErrnoValue != DFX_NO_ERRNO)
57template<
int ErrnoValue,
auto ErrorCode,
typename F,
typename ... Args>
58requires std::invocable<F, Args...>
59auto safeInvokeValueFFI(std::shared_ptr<spdlog::logger> logger, F && f, Args && ... args)
noexcept
61 using ResultType = std::invoke_result_t<F, Args...>;
62 static_assert(!std::is_void_v<ResultType>,
63 "safeInvokeValueFFI cannot be used with void functions. Use safeInvokeFFI instead.");
67 return std::invoke(std::forward<F>(f), std::forward<Args>(args)...);
71 if (logger !=
nullptr)
74 catch (std::exception
const & e)
76 DFX_LLOG(logger, spdlog::level::err,
"An error occurred: {}", e.what());
80 DFX_LLOG(logger, spdlog::level::err,
"An unknown error occurred");
83 if constexpr (ErrnoValue != DFX_NO_ERRNO)
85 return static_cast<ResultType
>(ErrorCode);
88template<
int ErrnoValue, auto ErrorCode = DFX_ERROR>
89auto setErrnoAndReturn()
noexcept
92 if constexpr (!std::is_same_v<
decltype(ErrorCode),
VoidReturnTag>)
96template<
int ErrnoValue,
auto ErrorCode =
DFX_ERROR,
typename ... Args>
97auto setErrnoLogAndReturn(std::shared_ptr<spdlog::logger> logger, std::format_string<Args ...> message, Args && ... args)
noexcept
99 if (logger !=
nullptr)
100 DFX_LLOG_ERROR(logger, message, std::forward<Args>(args)...);
102 return setErrnoAndReturn<ErrnoValue, ErrorCode>();
static void printToLogger(Exception const &e, spdlog::level::level_enum lvl=spdlog::level::err, std::string const &loggerName="", std::size_t initialIndentLevel=0, std::string const &logPattern=noFileLogPattern, std::string const ¤tLogPattern=defaultLogPattern)
Log an exception (including nested exceptions) using a logger name.