[gnome-software] trivial: Convert GDBus errors from flatpak
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] trivial: Convert GDBus errors from flatpak
- Date: Sun, 25 Sep 2016 08:28:20 +0000 (UTC)
commit ffe6d4f797cc5694c91c6e3d851010419f2be591
Author: Richard Hughes <richard hughsie com>
Date: Sun Sep 25 09:07:09 2016 +0100
trivial: Convert GDBus errors from flatpak
src/gs-utils.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++
src/gs-utils.h | 1 +
src/plugins/gs-flatpak.c | 4 +++
3 files changed, 64 insertions(+), 0 deletions(-)
---
diff --git a/src/gs-utils.c b/src/gs-utils.c
index bc31b15..f639d2e 100644
--- a/src/gs-utils.c
+++ b/src/gs-utils.c
@@ -549,6 +549,65 @@ gs_utils_error_strip_unique_id (GError *error)
}
/**
+ * gs_utils_error_convert_gdbus:
+ * @perror: a pointer to a #GError, or %NULL
+ *
+ * Converts the #GDBusError to an error with a GsPluginError domain.
+ *
+ * Returns: %TRUE if the error was converted, or already correct
+ **/
+gboolean
+gs_utils_error_convert_gdbus (GError **perror)
+{
+ GError *error = perror != NULL ? *perror : NULL;
+
+ /* not set */
+ if (error == NULL)
+ return FALSE;
+ if (error->domain == GS_PLUGIN_ERROR)
+ return TRUE;
+ if (error->domain != G_DBUS_ERROR)
+ return FALSE;
+ switch (error->code) {
+ case G_DBUS_ERROR_FAILED:
+ case G_DBUS_ERROR_NO_REPLY:
+ case G_DBUS_ERROR_TIMEOUT:
+ error->code = GS_PLUGIN_ERROR_FAILED;
+ break;
+ case G_DBUS_ERROR_IO_ERROR:
+ case G_DBUS_ERROR_NAME_HAS_NO_OWNER:
+ case G_DBUS_ERROR_NOT_SUPPORTED:
+ case G_DBUS_ERROR_SERVICE_UNKNOWN:
+ case G_DBUS_ERROR_UNKNOWN_INTERFACE:
+ case G_DBUS_ERROR_UNKNOWN_METHOD:
+ case G_DBUS_ERROR_UNKNOWN_OBJECT:
+ case G_DBUS_ERROR_UNKNOWN_PROPERTY:
+ error->code = GS_PLUGIN_ERROR_NOT_SUPPORTED;
+ break;
+ case G_DBUS_ERROR_NO_MEMORY:
+ error->code = GS_PLUGIN_ERROR_NO_SPACE;
+ break;
+ case G_DBUS_ERROR_ACCESS_DENIED:
+ case G_DBUS_ERROR_AUTH_FAILED:
+ error->code = GS_PLUGIN_ERROR_NO_SECURITY;
+ break;
+ case G_DBUS_ERROR_NO_NETWORK:
+ error->code = GS_PLUGIN_ERROR_NO_NETWORK;
+ break;
+ case G_DBUS_ERROR_INVALID_FILE_CONTENT:
+ error->code = GS_PLUGIN_ERROR_INVALID_FORMAT;
+ break;
+ default:
+ g_warning ("can't reliably fixup error code %i in domain %s",
+ error->code, g_quark_to_string (error->domain));
+ error->code = GS_PLUGIN_ERROR_FAILED;
+ break;
+ }
+ error->domain = GS_PLUGIN_ERROR;
+ return TRUE;
+}
+
+/**
* gs_utils_error_convert_gio:
* @perror: a pointer to a #GError, or %NULL
*
diff --git a/src/gs-utils.h b/src/gs-utils.h
index 72d432a..3a55cd3 100644
--- a/src/gs-utils.h
+++ b/src/gs-utils.h
@@ -74,6 +74,7 @@ void gs_utils_error_add_unique_id (GError **error,
GsApp *app);
void gs_utils_error_strip_unique_id (GError *error);
gboolean gs_utils_error_convert_gio (GError **perror);
+gboolean gs_utils_error_convert_gdbus (GError **perror);
gboolean gs_utils_error_convert_gdk_pixbuf(GError **perror);
gboolean gs_utils_error_convert_json_glib (GError **perror);
gboolean gs_utils_error_convert_appstream (GError **perror);
diff --git a/src/plugins/gs-flatpak.c b/src/plugins/gs-flatpak.c
index 95b9931..fb85cde 100644
--- a/src/plugins/gs-flatpak.c
+++ b/src/plugins/gs-flatpak.c
@@ -72,6 +72,10 @@ gs_plugin_flatpak_error_convert (GError **perror)
if (gs_utils_error_convert_gio (perror))
return;
+ /* this are allowed for low-level errors */
+ if (gs_utils_error_convert_gdbus (perror))
+ return;
+
/* custom to this plugin */
if (error->domain == FLATPAK_ERROR) {
switch (error->code) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]