* mu: small error-handling improvement

This commit is contained in:
djcb 2012-10-24 23:49:54 +03:00
parent dc5f27c899
commit f19ede80ce
2 changed files with 21 additions and 14 deletions

View File

@ -131,7 +131,8 @@ runtime_free (void)
void
mu_runtime_uninit (void)
{
g_return_if_fail (_initialized);
if (!_initialized)
return;
runtime_free ();

View File

@ -56,23 +56,26 @@ handle_error (MuConfig *conf, GError *err)
switch (err->code) {
case MU_ERROR_XAPIAN_CANNOT_GET_WRITELOCK:
g_print ("maybe mu is already running?\n");
g_printerr ("maybe mu is already running?\n");
break;
case MU_ERROR_XAPIAN_CORRUPTION:
case MU_ERROR_XAPIAN_NOT_UP_TO_DATE:
g_print ("database needs update; try 'mu index --rebuild'\n");
g_printerr ("database needs update; "
"try 'mu index --rebuild'\n");
break;
case MU_ERROR_XAPIAN_IS_EMPTY:
g_print ("database is empty; try 'mu index'");
g_printerr ("database is empty; try 'mu index'");
break;
case MU_ERROR_IN_PARAMETERS:
if (mu_config_cmd_is_valid(conf->cmd))
if (conf && mu_config_cmd_is_valid(conf->cmd))
mu_config_show_help (conf->cmd);
break;
default:break; /* nothing to do */
default:
break; /* nothing to do */
}
g_warning ("%s", err->message);
if (err)
g_printerr ("mu: %s\n", err->message);
}
@ -86,12 +89,16 @@ main (int argc, char *argv[])
setlocale (LC_ALL, "");
g_type_init ();
conf = mu_config_init (&argc, &argv);
if (!conf)
return 1;
else if (conf->version) {
err = NULL;
rv = MU_OK;
conf = mu_config_init (&argc, &argv, &err);
if (!conf) {
rv = err ? (MuError)err->code : MU_ERROR;
goto cleanup;
} else if (conf->version) {
show_version ();
return 0;
goto cleanup;
}
/* nothing to do */
@ -103,13 +110,12 @@ main (int argc, char *argv[])
return 1;
}
err = NULL;
rv = mu_cmd_execute (conf, &err);
cleanup:
handle_error (conf, err);
g_clear_error (&err);
mu_config_uninit (conf);
mu_runtime_uninit ();