summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2018-07-10 14:29:18 +0200
committerAlexander Larsson <alexander.larsson@gmail.com>2018-07-10 19:26:16 +0200
commitaecc6285d6ddc9d49cc9e90b0210d22e6f472483 (patch)
tree942d3bc1804b3c6fbc47361c55c7a3712da49cbd
parentc9a9b3a1ee7a63490adc00c51ff8e1c9777fa055 (diff)
downloadflatpak-aecc6285d6ddc9d49cc9e90b0210d22e6f472483.tar.gz
utils: Add flatpak_fail_error that takes an error code
This makes it easy to return FlatpakErrors
-rw-r--r--common/flatpak-utils-private.h5
-rw-r--r--common/flatpak-utils.c14
-rw-r--r--session-helper/Makefile.am.inc2
3 files changed, 20 insertions, 1 deletions
diff --git a/common/flatpak-utils-private.h b/common/flatpak-utils-private.h
index c64b90e8..7a63defb 100644
--- a/common/flatpak-utils-private.h
+++ b/common/flatpak-utils-private.h
@@ -31,6 +31,7 @@
#include "flatpak-dbus-generated.h"
#include "flatpak-document-dbus-generated.h"
#include "flatpak-context-private.h"
+#include "flatpak-error.h"
#include <ostree.h>
#include <json-glib/json-glib.h>
@@ -64,6 +65,10 @@ typedef void (*FlatpakLoadUriProgress) (guint64 downloaded_bytes,
*/
#define flatpak_fail glnx_throw
+gboolean flatpak_fail_error (GError **error,
+ FlatpakError code,
+ const char *fmt, ...) G_GNUC_PRINTF (3,4);
+
void flatpak_debug2 (const char *format,
...) G_GNUC_PRINTF (1, 2);
diff --git a/common/flatpak-utils.c b/common/flatpak-utils.c
index 2deaf3cb..65dd7816 100644
--- a/common/flatpak-utils.c
+++ b/common/flatpak-utils.c
@@ -78,6 +78,20 @@ flatpak_error_quark (void)
return (GQuark) quark_volatile;
}
+gboolean
+flatpak_fail_error (GError **error, FlatpakError code, const char *fmt, ...)
+{
+ if (error == NULL)
+ return FALSE;
+
+ va_list args;
+ va_start (args, fmt);
+ GError *new = g_error_new_valist (FLATPAK_ERROR, code, fmt, args);
+ va_end (args);
+ g_propagate_error (error, g_steal_pointer (&new));
+ return FALSE;
+}
+
void
flatpak_debug2 (const char *format, ...)
{
diff --git a/session-helper/Makefile.am.inc b/session-helper/Makefile.am.inc
index ed2d5341..7ea49bf0 100644
--- a/session-helper/Makefile.am.inc
+++ b/session-helper/Makefile.am.inc
@@ -13,4 +13,4 @@ flatpak_session_helper_SOURCES = \
$(NULL)
flatpak_session_helper_LDADD = $(AM_LDADD) $(BASE_LIBS) libflatpak-common.la
-flatpak_session_helper_CFLAGS = $(AM_CFLAGS) $(BASE_CFLAGS) $(SOUP_CFLAGS) $(OSTREE_CFLAGS) $(GSYSTEM_CFLAGS) $(JSON_CFLAGS)
+flatpak_session_helper_CFLAGS = $(AM_CFLAGS) $(BASE_CFLAGS) $(SOUP_CFLAGS) $(OSTREE_CFLAGS) $(GSYSTEM_CFLAGS) $(JSON_CFLAGS) -DFLATPAK_COMPILATION