lib: improve store error messages

Use xapian_try_result
This commit is contained in:
Dirk-Jan C. Binnema 2023-07-23 21:03:02 +03:00
parent d374d94031
commit 72f43f11df
2 changed files with 8 additions and 21 deletions

View File

@ -63,17 +63,10 @@ public:
* @return A store or an error.
*/
static Result<Store> make(const std::string& path,
Options opts=Options::None) noexcept try {
return Ok(Store{path, opts});
} catch (const Mu::Error& me) {
return Err(me);
Options opts=Options::None) noexcept {
return xapian_try_result(
[&]{return Ok(Store{path, opts});});
}
/* LCOV_EXCL_START */
catch (...) {
return Err(Error::Code::Internal, "failed to create store");
}
/* LCOV_EXCL_STOP */
/**
* Construct a store for a not-yet-existing document database
@ -86,18 +79,10 @@ public:
*/
static Result<Store> make_new(const std::string& path,
const std::string& root_maildir,
Option<const Config&> conf={}) noexcept try {
return Ok(Store(path, root_maildir, conf));
} catch (const Mu::Error& me) {
return Err(me);
Option<const Config&> conf={}) noexcept {
return xapian_try_result(
[&]{return Ok(Store(path, root_maildir, conf));});
}
/* LCOV_EXCL_START */
catch (...) {
return Err(Error::Code::Internal, "failed to create new store");
}
/* LCOV_EXCL_STOP */
/**
* Move CTOR

View File

@ -76,6 +76,8 @@ template <typename Func> auto
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");
} catch (const Xapian::Error& xerr) {
return Err(Error::Code::Xapian, "{}", xerr.get_error_string());
} catch (const std::runtime_error& re) {