result: add Err which takes a GError

Convenience
This commit is contained in:
Dirk-Jan C. Binnema 2022-03-26 16:17:17 +02:00
parent 8ed09a9a82
commit 55402622b9
1 changed files with 17 additions and 0 deletions

View File

@ -99,6 +99,23 @@ Err(Error::Code errcode, const char* frm, ...)
return Err(errcode, std::move(str));
}
__attribute__((format(printf, 3, 0)))
static inline tl::unexpected<Error>
Err(Error::Code errcode, GError **err, const char* frm, ...)
{
va_list args;
va_start(args, frm);
auto str{vformat(frm, args)};
va_end(args);
if (err && *err)
str += format(" (%s)", (*err)->message ? (*err)->message : "");
g_clear_error(err);
return Err(errcode, std::move(str));
}
}// namespace Mu
#endif /* MU_RESULT_HH__ */