diff --git a/lib/mu-xapian-db.cc b/lib/mu-xapian-db.cc index ddc2c115..bd5f817c 100644 --- a/lib/mu-xapian-db.cc +++ b/lib/mu-xapian-db.cc @@ -51,12 +51,6 @@ XapianDb::read_only() const return !std::holds_alternative(db_); } -const std::string& -XapianDb::path() const -{ - return path_; -} - void XapianDb::set_timestamp(const std::string_view key) { @@ -102,8 +96,7 @@ make_db(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()} // default -{ + batch_size_{Config(*this).get()/*default*/} { if (flavor == Flavor::CreateOverwrite) set_timestamp(MetadataIface::created_key); diff --git a/lib/mu-xapian-db.hh b/lib/mu-xapian-db.hh index 27921b77..24dbf593 100644 --- a/lib/mu-xapian-db.hh +++ b/lib/mu-xapian-db.hh @@ -50,6 +50,8 @@ template void xapian_try(Func&& func) noexcept try { func(); +} catch (const Mu::Error& me) { + mu_critical("{}: mu error '{}'", __func__, me.what()); } catch (const Xapian::Error& xerr) { mu_critical("{}: xapian error '{}'", __func__, xerr.get_msg()); } catch (const std::runtime_error& re) { @@ -64,6 +66,9 @@ template > auto xapian_try(Func&& func, Default&& def) noexcept -> std::decay_t try { return func(); +} catch (const Mu::Error& me) { + mu_critical("{}: mu error '{}'", __func__, me.what()); + return static_cast(def); } catch (const Xapian::DocNotFoundError& xerr) { return static_cast(def); } catch (const Xapian::Error& xerr) { @@ -84,6 +89,9 @@ template auto xapian_try_result(Func&& func) noexcept -> std::decay_t try { return func(); + +} catch (const Mu::Error& me) { + return Err(std::move(me)); } catch (const Xapian::DatabaseNotFoundError& nferr) { return Err(Error{Error::Code::Xapian, "failed to open database"}. add_hint("Try (re)creating using `mu init'")); @@ -128,13 +136,13 @@ struct MetadataIface { /// In-memory db -struct MemDb: public MetadataIface { +struct MemDb final: public MetadataIface { /** * Create a new memdb * * @param readonly read-only? (for testing) */ - MemDb(bool readonly=false):read_only_{readonly} {} + explicit MemDb(bool readonly=false):read_only_{readonly} {} /** * Set some metadata @@ -188,7 +196,7 @@ private: /** * Fairly thin wrapper around Xapian::Database and Xapian::WritableDatabase */ -class XapianDb: public MetadataIface { +class XapianDb final: public MetadataIface { public: /** * Type of database to create. @@ -211,8 +219,9 @@ public: /** * DTOR */ - ~XapianDb() { - if (!read_only()) + ~XapianDb() override { + // shouldn't use read_only() here, since that's virtual. + if (std::holds_alternative(db_)) request_commit(true/*force*/); mu_debug("closing db"); } @@ -237,7 +246,9 @@ public: * * @return path to database */ - const std::string& path() const; + const std::string& path() const { + return path_; + } /** * Get a description of the Xapian database @@ -500,7 +511,7 @@ private: Xapian::WritableDatabase& wdb(); std::string path_; - DbType db_; + DbType db_; size_t changes_{}; bool in_transaction_{}; size_t batch_size_;