mirror of https://github.com/djcb/mu.git
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.
This commit is contained in:
parent
b222a8a3f5
commit
f3f4ea65ab
|
@ -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<Config::Id::BatchSize>()}
|
||||
|
|
|
@ -76,9 +76,15 @@ template <typename Func> auto
|
|||
xapian_try_result(Func&& func) noexcept -> std::decay_t<decltype(func())>
|
||||
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_;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue