provide end-user hints and show them
Only a few for now.
This commit is contained in:
@ -241,7 +241,8 @@ Store::Store(const std::string& path, Store::Options opts)
|
|||||||
if (s_version < 500)
|
if (s_version < 500)
|
||||||
throw Mu::Error(Error::Code::CannotReinit,
|
throw Mu::Error(Error::Code::CannotReinit,
|
||||||
"old schema ({}) is too old to re-initialize from",
|
"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()};
|
const auto old_root_maildir{root_maildir()};
|
||||||
|
|
||||||
MemDb mem_db;
|
MemDb mem_db;
|
||||||
@ -258,7 +259,8 @@ Store::Store(const std::string& path, Store::Options opts)
|
|||||||
if (s_version != ExpectedSchemaVersion)
|
if (s_version != ExpectedSchemaVersion)
|
||||||
throw Mu::Error(Error::Code::SchemaMismatch,
|
throw Mu::Error(Error::Code::SchemaMismatch,
|
||||||
"expected schema-version {}, but got {}",
|
"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,
|
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.
|
// we shouldn't mix ngrams/non-ngrams messages.
|
||||||
if (any_of(msg.options() & Message::Options::SupportNgrams) !=
|
if (any_of(msg.options() & Message::Options::SupportNgrams) !=
|
||||||
any_of(message_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
|
/* add contacts from this message to cache; this cache
|
||||||
* also determines whether those contacts are _personal_, i.e. match
|
* also determines whether those contacts are _personal_, i.e. match
|
||||||
|
|||||||
@ -77,7 +77,8 @@ xapian_try_result(Func&& func) noexcept -> std::decay_t<decltype(func())>
|
|||||||
try {
|
try {
|
||||||
return func();
|
return func();
|
||||||
} catch (const Xapian::DatabaseLockError& dlerr) {
|
} 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) {
|
} catch (const Xapian::Error& xerr) {
|
||||||
return Err(Error::Code::Xapian, "{}", xerr.get_error_string());
|
return Err(Error::Code::Xapian, "{}", xerr.get_error_string());
|
||||||
} catch (const std::runtime_error& re) {
|
} catch (const std::runtime_error& re) {
|
||||||
|
|||||||
23
mu/mu.cc
23
mu/mu.cc
@ -61,26 +61,11 @@ handle_result(const Result<void>& res, const Mu::Options& opts)
|
|||||||
mu_printerrln("{}{}{}",
|
mu_printerrln("{}{}{}",
|
||||||
col.fg(Color::BrightBlue), res.error().what(), col.reset());
|
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.
|
// perhaps give some useful hint on how to solve it.
|
||||||
switch (res.error().code()) {
|
if (!res.error().hint().empty())
|
||||||
case Error::Code::InvalidArgument:
|
mu_printerrln("{}hint{}: {}{}{}",
|
||||||
break;
|
col.fg(Color::Blue), col.reset(),
|
||||||
case Error::Code::StoreLock:
|
col.fg(Color::Green), res.error().hint(), col.reset());
|
||||||
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());
|
|
||||||
|
|
||||||
return res.error().exit_code();
|
return res.error().exit_code();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user