Make app_load_config() return any error

This commit is contained in:
Přemysl Eric Janouch 2016-09-28 00:14:11 +02:00
parent e14c9af40f
commit 474bcb518a
Signed by: p
GPG Key ID: B715679E3A361BE6
1 changed files with 15 additions and 11 deletions

View File

@ -317,7 +317,7 @@ app_load_config_values (Application *self, GKeyFile *kf)
} }
static void static void
app_load_config (Application *self) app_load_config (Application *self, GError **e)
{ {
GKeyFile *kf = g_key_file_new (); GKeyFile *kf = g_key_file_new ();
GPtrArray *paths = g_ptr_array_new (); GPtrArray *paths = g_ptr_array_new ();
@ -330,22 +330,20 @@ app_load_config (Application *self)
// XXX: if there are dashes in the final path component, // XXX: if there are dashes in the final path component,
// the function tries to replace them with directory separators, // the function tries to replace them with directory separators,
// which is completely undocumented // which is completely undocumented
GError *e = NULL; GError *error = NULL;
g_key_file_load_from_dirs (kf, g_key_file_load_from_dirs (kf,
PROJECT_NAME G_DIR_SEPARATOR_S PROJECT_NAME ".conf", PROJECT_NAME G_DIR_SEPARATOR_S PROJECT_NAME ".conf",
(const gchar **) paths->pdata, NULL, 0, &e); (const gchar **) paths->pdata, NULL, 0, &error);
g_ptr_array_free (paths, TRUE); g_ptr_array_free (paths, TRUE);
// TODO: proper error handling showing all relevant information; // TODO: proper error handling showing all relevant information;
// we can afford that here since the terminal hasn't been initialized yet // we can afford that here since the terminal hasn't been initialized yet
if (e) if (!error)
{
if (e->code != G_KEY_FILE_ERROR_NOT_FOUND)
g_error ("%s: %s\n", _("Cannot load configuration"), e->message);
g_error_free (e);
}
else
app_load_config_values (self, kf); app_load_config_values (self, kf);
else if (error->code == G_KEY_FILE_ERROR_NOT_FOUND)
g_error_free (error);
else
g_propagate_error (e, error);
g_key_file_free (kf); g_key_file_free (kf);
} }
@ -421,7 +419,13 @@ app_init (Application *self, AppOptions *options, const gchar *filename)
app_reload_view (self); app_reload_view (self);
app_init_attrs (self); app_init_attrs (self);
app_load_config (self);
app_load_config (self, &error);
if (error)
{
g_printerr ("%s: %s\n", _("Cannot load configuration"), error->message);
exit (EXIT_FAILURE);
}
} }
static void static void