* 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 void
mu_runtime_uninit (void) mu_runtime_uninit (void)
{ {
g_return_if_fail (_initialized); if (!_initialized)
return;
runtime_free (); runtime_free ();

View File

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