From f3f4ea65abd8b93ced7aae799532cf56ff1e7db8 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Fri, 29 Dec 2023 11:00:36 +0200 Subject: [PATCH] xapian-db: improve some error messages Correctly handle re-opening a transaction after one has finished. Recognize some database opening errors and give some better user hints. Fixes #2615. --- lib/mu-xapian-db.cc | 2 +- lib/mu-xapian-db.hh | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/mu-xapian-db.cc b/lib/mu-xapian-db.cc index cfa1629f..a8c897a0 100644 --- a/lib/mu-xapian-db.cc +++ b/lib/mu-xapian-db.cc @@ -98,7 +98,7 @@ make_db(const std::string& db_path, Flavor flavor) } } -XapianDb::XapianDb(const std::string& db_path, Flavor flavor) : +XapianDb::XapianDb(const std::string& db_path, Flavor flavor): path_(make_path(db_path, flavor)), db_(make_db(path_, flavor)), batch_size_{Config(*this).get()} diff --git a/lib/mu-xapian-db.hh b/lib/mu-xapian-db.hh index 66b7bf8d..dd179157 100644 --- a/lib/mu-xapian-db.hh +++ b/lib/mu-xapian-db.hh @@ -76,9 +76,15 @@ template auto xapian_try_result(Func&& func) noexcept -> std::decay_t try { return func(); +} catch (const Xapian::DatabaseNotFoundError& nferr) { + return Err(Error{Error::Code::Xapian, "failed to open database"}. + add_hint("Perhaps try (re)creating using `mu index'")); } catch (const Xapian::DatabaseLockError& dlerr) { return Err(Error{Error::Code::StoreLock, "database locked"}. add_hint("Perhaps mu is already running?")); +} catch (const Xapian::DatabaseCorruptError& dcerr) { + return Err(Error{Error::Code::Xapian, "failed to read database"}. + add_hint("Try (re)creating using `mu index'")); } catch (const Xapian::Error& xerr) { return Err(Error::Code::Xapian, "{}", xerr.get_error_string()); } catch (const std::runtime_error& re) { @@ -186,7 +192,7 @@ public: }; /** - * XapianDb CTOR + * XapianDb CTOR. This may throw some Xapian exception. * * @param db_path path to the database * @param flavor kind of database @@ -422,6 +428,7 @@ public: wdb().begin_transaction(); } ++tx_level_; + mu_debug("ind'd tx level to {}", tx_level_); }); } @@ -443,6 +450,7 @@ public: changes_ = 0; } --tx_level_; + mu_debug("dec'd tx level to {}", tx_level_); }); } @@ -501,6 +509,7 @@ private: --tx_level_; changes_ = 0; wdb().begin_transaction(); + ++tx_level_; } }