provide end-user hints and show them

Only a few for now.
This commit is contained in:
Dirk-Jan C. Binnema
2023-09-16 11:07:03 +03:00
parent 3123f3e983
commit c78dafd723
3 changed files with 11 additions and 23 deletions

View File

@ -241,7 +241,8 @@ Store::Store(const std::string& path, Store::Options opts)
if (s_version < 500)
throw Mu::Error(Error::Code::CannotReinit,
"old schema ({}) is too old to re-initialize from",
s_version);
s_version).add_hint("Invoke 'mu init' without '--reinit'; "
"see mu-init(1) for details");
const auto old_root_maildir{root_maildir()};
MemDb mem_db;
@ -258,7 +259,8 @@ Store::Store(const std::string& path, Store::Options opts)
if (s_version != ExpectedSchemaVersion)
throw Mu::Error(Error::Code::SchemaMismatch,
"expected schema-version {}, but got {}",
ExpectedSchemaVersion, s_version);
ExpectedSchemaVersion, s_version).
add_hint("Please (re)initialize with 'mu init'; see mu-init(1) for details");
}
Store::Store(const std::string& path,
@ -348,7 +350,7 @@ Store::add_message(Message& msg, bool use_transaction, bool is_new)
// we shouldn't mix ngrams/non-ngrams messages.
if (any_of(msg.options() & Message::Options::SupportNgrams) !=
any_of(message_options() & Message::Options::SupportNgrams))
return Err(Error::Code::InvalidArgument, "incompatible message options");
return Err(Error::Code::InvalidArgument, "incompatible message options");
/* add contacts from this message to cache; this cache
* also determines whether those contacts are _personal_, i.e. match

View File

@ -77,7 +77,8 @@ xapian_try_result(Func&& func) noexcept -> std::decay_t<decltype(func())>
try {
return func();
} catch (const Xapian::DatabaseLockError& dlerr) {
return Err(Error::Code::StoreLock, "database locked");
return Err(Error{Error::Code::StoreLock, "database locked"}.
add_hint("Perhaps mu is already running?"));
} catch (const Xapian::Error& xerr) {
return Err(Error::Code::Xapian, "{}", xerr.get_error_string());
} catch (const std::runtime_error& re) {

View File

@ -61,26 +61,11 @@ handle_result(const Result<void>& res, const Mu::Options& opts)
mu_printerrln("{}{}{}",
col.fg(Color::BrightBlue), res.error().what(), col.reset());
mu_printerr("{}", col.fg(Color::Green));
// perhaps give some useful hint on how to solve it.
switch (res.error().code()) {
case Error::Code::InvalidArgument:
break;
case Error::Code::StoreLock:
mu_printerrln("Perhaps mu is already running?");
break;
case Error::Code::SchemaMismatch:
mu_printerrln("Please (re)initialize with 'mu init'; see mu-init(1) for details");
break;
case Error::Code::CannotReinit:
mu_printerrln("Invoke 'mu init' without '--reinit'; see mu-init(1) for details");
break;
default:
break; /* nothing to do */
}
mu_printerr("{}", col.reset());
if (!res.error().hint().empty())
mu_printerrln("{}hint{}: {}{}{}",
col.fg(Color::Blue), col.reset(),
col.fg(Color::Green), res.error().hint(), col.reset());
return res.error().exit_code();
}