aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2024-01-22 14:35:48 +0000
committerVsevolod Stakhov <vsevolod@rspamd.com>2024-01-22 14:42:06 +0000
commit4fd676e6f549151160005304ad825f48ebeb22fb (patch)
tree806dcf6bb1398db4cf3c297ea7b3a8eaca048f2d /src
parent66cc2d3d88dc48fbbffc59e64549b0ee1da4bcf4 (diff)
downloadrspamd-4fd676e6f549151160005304ad825f48ebeb22fb.tar.gz
rspamd-4fd676e6f549151160005304ad825f48ebeb22fb.zip
[Minor] Add some convenience methods
Diffstat (limited to 'src')
-rw-r--r--src/libutil/cxx/error.hxx27
1 files changed, 24 insertions, 3 deletions
diff --git a/src/libutil/cxx/error.hxx b/src/libutil/cxx/error.hxx
index 91f9d0cf4..4689d4276 100644
--- a/src/libutil/cxx/error.hxx
+++ b/src/libutil/cxx/error.hxx
@@ -1,11 +1,11 @@
-/*-
- * Copyright 2022 Vsevolod Stakhov
+/*
+ * Copyright 2024 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -126,6 +126,27 @@ public:
}
}
+ /**
+ * Convert into GError
+ * @return
+ */
+ auto into_g_error(GQuark quark) const -> GError *
+ {
+ return g_error_new(quark, error_code, "%s",
+ error_message.data());
+ }
+
+ /**
+ * Convenience alias for the `into_g_error`
+ * @param err
+ */
+ auto into_g_error_set(GQuark quark, GError **err) const -> void
+ {
+ if (err && *err == nullptr) {
+ *err = into_g_error(quark);
+ }
+ }
+
public:
std::string_view error_message;
int error_code;