Skip to content

Commit

Permalink
utils: Add flatpak_fail_error that takes an error code
Browse files Browse the repository at this point in the history
This makes it easy to return FlatpakErrors
  • Loading branch information
alexlarsson committed Jul 10, 2018
1 parent c9a9b3a commit aecc628
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
5 changes: 5 additions & 0 deletions common/flatpak-utils-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -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);

Expand Down
14 changes: 14 additions & 0 deletions common/flatpak-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...)
{
Expand Down
2 changes: 1 addition & 1 deletion session-helper/Makefile.am.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit aecc628

Please sign in to comment.