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) 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,

View File

@ -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) {

View File

@ -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();
} }