From 9d0fbdd0b4f023c3e349e024f068fee4020ffbfa Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 28 Sep 2018 07:44:15 -0400 Subject: [PATCH] FlatpakContext: Avoid flatpak_fail flatpak_fail is a convenient shortcut, but falls short for actual error reporting. Use proper G_OPTION_ERROR error codes here. Closes: #2150 Approved by: alexlarsson --- common/flatpak-context.c | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/common/flatpak-context.c b/common/flatpak-context.c index b235ec0f..15097a1e 100644 --- a/common/flatpak-context.c +++ b/common/flatpak-context.c @@ -1111,14 +1111,26 @@ option_add_generic_policy_cb (const gchar *option_name, t = strchr (value, '='); if (t == NULL) - return flatpak_fail (error, "--policy arguments must be in the form SUBSYSTEM.KEY=[!]VALUE"); + { + g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, + _("--policy arguments must be in the form SUBSYSTEM.KEY=[!]VALUE")); + return FALSE; + } policy_value = t + 1; key = g_strndup (value, t - value); if (strchr (key, '.') == NULL) - return flatpak_fail (error, "--policy arguments must be in the form SUBSYSTEM.KEY=[!]VALUE"); + { + g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, + _("--policy arguments must be in the form SUBSYSTEM.KEY=[!]VALUE")); + return FALSE; + } if (policy_value[0] == '!') - return flatpak_fail (error, "--policy values can't start with \"!\""); + { + g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, + _("--policy values can't start with \"!\"")); + return FALSE; + } flatpak_context_apply_generic_policy (context, key, policy_value); @@ -1139,14 +1151,26 @@ option_remove_generic_policy_cb (const gchar *option_name, t = strchr (value, '='); if (t == NULL) - return flatpak_fail (error, "--policy arguments must be in the form SUBSYSTEM.KEY=[!]VALUE"); + { + g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, + _("--policy arguments must be in the form SUBSYSTEM.KEY=[!]VALUE")); + return FALSE; + } policy_value = t + 1; key = g_strndup (value, t - value); if (strchr (key, '.') == NULL) - return flatpak_fail (error, "--policy arguments must be in the form SUBSYSTEM.KEY=[!]VALUE"); + { + g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, + _("--policy arguments must be in the form SUBSYSTEM.KEY=[!]VALUE")); + return FALSE; + } if (policy_value[0] == '!') - return flatpak_fail (error, "--policy values can't start with \"!\""); + { + g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, + _("--policy values can't start with \"!\"")); + return FALSE; + } extended_value = g_strconcat ("!", policy_value, NULL);