* mu.cc: give user some advise if an error occured

This commit is contained in:
Dirk-Jan C. Binnema 2011-09-03 10:49:19 +03:00
parent 8ab3ff1fec
commit 8d52c8b5a1
1 changed files with 40 additions and 3 deletions

View File

@ -24,18 +24,55 @@
#include "mu-cmd.h"
#include "mu-runtime.h"
static void
handle_error (GError *err)
{
const char *advise;
if (!err)
return; /* nothing to do */
advise = NULL;
switch (err->code) {
case MU_ERROR_XAPIAN_CANNOT_GET_WRITELOCK:
advise = "maybe mu is already running?";
break;
case MU_ERROR_XAPIAN_CORRUPTION:
case MU_ERROR_XAPIAN_NOT_UP_TO_DATE:
advise = "please try 'mu index --rebuild'";
break;
case MU_ERROR_XAPIAN_IS_EMPTY:
advise = "please try 'mu index'";
break;
default:
break; /* nothing to do */
}
g_warning ("%s", err->message);
if (advise)
g_message ("%s", advise);
}
int
main (int argc, char *argv[])
{
int rv;
GError *err;
MuError rv;
if (!mu_runtime_init_from_cmdline (&argc, &argv, "mu"))
return 1;
rv = mu_cmd_execute (mu_runtime_config());
err = NULL;
rv = mu_cmd_execute (mu_runtime_config(), &err);
handle_error (err);
g_clear_error (&err);
mu_runtime_uninit ();
return rv;
}