keyfile: Add "in group" to GError message consistently

This originated with https://github.com/GNOME/ostree/pull/23
It's nicer for the user if we also mention which group the expected
key would be in.

And in fact, every other error *except* _get_value() already had it.

https://bugzilla.gnome.org/show_bug.cgi?id=741226
This commit is contained in:
Colin Walters 2014-12-07 16:00:55 -05:00
parent 7966f27882
commit a12f546b3b

View File

@ -1648,6 +1648,17 @@ g_key_file_get_groups (GKeyFile *key_file,
return groups; return groups;
} }
static void
set_not_found_key_error (const char *group_name,
const char *key,
GError **error)
{
g_set_error (error, G_KEY_FILE_ERROR,
G_KEY_FILE_ERROR_KEY_NOT_FOUND,
_("Key file does not have key '%s' in group '%s'"),
key, group_name);
}
/** /**
* g_key_file_get_value: * g_key_file_get_value:
* @key_file: a #GKeyFile * @key_file: a #GKeyFile
@ -1699,9 +1710,7 @@ g_key_file_get_value (GKeyFile *key_file,
if (pair) if (pair)
value = g_strdup (pair->value); value = g_strdup (pair->value);
else else
g_set_error (error, G_KEY_FILE_ERROR, set_not_found_key_error (group_name, key, error);
G_KEY_FILE_ERROR_KEY_NOT_FOUND,
_("Key file does not have key '%s'"), key);
return value; return value;
} }
@ -3082,10 +3091,7 @@ g_key_file_set_key_comment (GKeyFile *key_file,
if (key_node == NULL) if (key_node == NULL)
{ {
g_set_error (error, G_KEY_FILE_ERROR, set_not_found_key_error (group->name, key, error);
G_KEY_FILE_ERROR_KEY_NOT_FOUND,
_("Key file does not have key '%s' in group '%s'"),
key, group->name);
return FALSE; return FALSE;
} }
@ -3274,10 +3280,7 @@ g_key_file_get_key_comment (GKeyFile *key_file,
if (key_node == NULL) if (key_node == NULL)
{ {
g_set_error (error, G_KEY_FILE_ERROR, set_not_found_key_error (group->name, key, error);
G_KEY_FILE_ERROR_KEY_NOT_FOUND,
_("Key file does not have key '%s' in group '%s'"),
key, group->name);
return NULL; return NULL;
} }
@ -3841,10 +3844,7 @@ g_key_file_remove_key (GKeyFile *key_file,
if (!pair) if (!pair)
{ {
g_set_error (error, G_KEY_FILE_ERROR, set_not_found_key_error (group->name, key, error);
G_KEY_FILE_ERROR_KEY_NOT_FOUND,
_("Key file does not have key '%s' in group '%s'"),
key, group->name);
return FALSE; return FALSE;
} }