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
This commit is contained in:
Matthias Clasen
2018-09-28 07:44:15 -04:00
committed by Atomic Bot
parent df4df62d04
commit 9d0fbdd0b4

View File

@@ -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);