From 55402622b95ba70f8f07f652253c1366e108c4b3 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Sat, 26 Mar 2022 16:17:17 +0200 Subject: [PATCH] result: add Err which takes a GError Convenience --- lib/utils/mu-result.hh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/utils/mu-result.hh b/lib/utils/mu-result.hh index 58b2b322..ea568aad 100644 --- a/lib/utils/mu-result.hh +++ b/lib/utils/mu-result.hh @@ -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 +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__ */