Go to the documentation of this file.
19 #include <tl/expected.hpp>
36 template <
class TT,
class TE = Error>
41 template <
class TT,
class TE>
44 tl::expected<TT, TE>& wrapper,
45 char const* wrapper_cstr,
49 "[FARM_UNWRAP failed in {}:{}]", detail.file, detail.line);
51 "expected type `{}` does not contain a valid value", wrapper_cstr);
52 if (!detail.msg.empty()) {
53 ::fmt::print(stderr,
"{}", detail.msg);
55 ::fmt::print(stderr,
"{}", wrapper.error());
66 #ifdef FARM_ERROR_CALLSTACK_DISABLED
68 #define FARM_ERROR_DETAIL(...) \
69 ::farm_ng::ErrorDetail { \
70 .file = "n/a", .line = 0, .msg = FARM_FORMAT(__VA_ARGS__) \
75 #define FARM_ERROR_DETAIL(...) \
76 ::farm_ng::ErrorDetail { \
77 .file = __FILE__, .line = __LINE__, .msg = FARM_FORMAT(__VA_ARGS__) \
81 #define FARM_ERROR_REPORT(cstr, ...) \
83 .details = { FARM_ERROR_DETAIL(cstr, ##__VA_ARGS__) } \
86 #define FARM_UNEXPECTED(cstr, ...) \
87 ::tl::make_unexpected(FARM_ERROR_REPORT(cstr, ##__VA_ARGS__))
91 #define FARM_TRY(Type, var, expression) \
92 auto maybe##var = (expression); \
94 auto error = maybe##var.error(); \
95 error.details.emplace_back( \
96 FARM_ERROR_DETAIL("FARM_TRY propagated error.\n")); \
97 return ::tl::make_unexpected(error); \
99 Type var = ::std::move(*maybe##var);
101 #define FARM_ASSERT_OR_ERROR(condition, ...) \
102 if (!(condition)) { \
103 return FARM_UNEXPECTED( \
104 "bool({}) not true.\n{}", #condition, FARM_FORMAT(__VA_ARGS__)); \
110 template <
class TT,
class TE = Error>
Definition: backtrace.cpp:102
std::optional< TT > fromExpected(Expected< TT, TE > expected)
Definition: expected.h:111
Definition: expected.h:28
auto operator<<(std::ostream &os, Error const &error) -> std::ostream &
Definition: expected.cpp:19
farm_ng_core_logging Console string format and CHECK macros Depends on expected(both part of future c++standards)
static auto impl(tl::expected< TT, TE > &wrapper, char const *wrapper_cstr, ::farm_ng::ErrorDetail detail) -> decltype(*wrapper)
Definition: expected.h:43
std::vector< ErrorDetail > details
Definition: expected.h:29
#define FARM_UNEXPECTED(cstr,...)
Definition: expected.h:86
Expected< TT > fromOptional(std::optional< TT > optional)
Definition: expected.h:116
tl::expected< TT, TE > Expected
Definition: expected.h:37
Definition: expected.h:34