From dce924da9cf30c183bc8a8831ae95fcb2bb9f488 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Tue, 15 Feb 2022 22:28:21 +0200 Subject: [PATCH] mu-error: Better support for GError Allow filling a GError from a Mu::Error --- lib/utils/mu-error.hh | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/utils/mu-error.hh b/lib/utils/mu-error.hh index 2b5ae9a1..92ddd5ef 100644 --- a/lib/utils/mu-error.hh +++ b/lib/utils/mu-error.hh @@ -22,6 +22,7 @@ #include #include "mu-utils.hh" +#include "mu-util.h" #include namespace Mu { @@ -69,7 +70,7 @@ struct Error final : public std::exception { } Error(Error&& rhs) = default; - Error(const Error& rhs) = delete; + Error(const Error& rhs) = default; /** * Build an error from a GError an error-code and a format string @@ -118,7 +119,18 @@ struct Error final : public std::exception { */ Code code() const { return code_; } - private: + + /** + * Fill a GError with the error information + * + * @param err GError** (or NULL) + */ + void fill_g_error(GError **err) { + g_set_error(err, MU_ERROR_DOMAIN, static_cast(code_), + "%s", what_.c_str()); + } + +private: const Code code_; std::string what_; };