From acf28d6f734402202be4404086e20d2739466aa8 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 21 Feb 2018 13:40:36 +0100 Subject: Catch xapian exceptions --- common/fulltextindex.cpp | 71 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 53 insertions(+), 18 deletions(-) (limited to 'common') diff --git a/common/fulltextindex.cpp b/common/fulltextindex.cpp index 839079d..355f1ca 100644 --- a/common/fulltextindex.cpp +++ b/common/fulltextindex.cpp @@ -65,29 +65,43 @@ void FulltextIndex::add(const QByteArray &key, const QListreplace_document(idterm, document); + writableDatabase()->replace_document(idterm, document); + } + catch (const Xapian::Error &error) { + SinkError() << "Exception during Xapian commit_transaction:" << error.get_msg().c_str(); + //FIXME we should somehow retry the transaction... + Q_ASSERT(false); + } } void FulltextIndex::commitTransaction() { if (mHasTransactionOpen) { Q_ASSERT(mDb); - writableDatabase()->commit_transaction(); - mHasTransactionOpen = false; + try { + writableDatabase()->commit_transaction(); + mHasTransactionOpen = false; + } + catch (const Xapian::Error &error) { + SinkError() << "Exception during Xapian commit_transaction:" << error.get_msg().c_str(); + //FIXME we should somehow retry the transaction... + Q_ASSERT(false); + } } } @@ -95,8 +109,15 @@ void FulltextIndex::abortTransaction() { if (mHasTransactionOpen) { Q_ASSERT(mDb); - writableDatabase()->cancel_transaction(); - mHasTransactionOpen = false; + try { + writableDatabase()->cancel_transaction(); + mHasTransactionOpen = false; + } + catch (const Xapian::Error &error) { + SinkError() << "Exception during Xapian cancel_transaction:" << error.get_msg().c_str(); + //FIXME we should somehow retry the transaction... + Q_ASSERT(false); + } } } @@ -105,8 +126,15 @@ Xapian::WritableDatabase* FulltextIndex::writableDatabase() Q_ASSERT(dynamic_cast(mDb)); auto db = static_cast(mDb); if (!mHasTransactionOpen) { - db->begin_transaction(); - mHasTransactionOpen = true; + try { + db->begin_transaction(); + mHasTransactionOpen = true; + } + catch (const Xapian::Error &error) { + SinkError() << "Exception during Xapian begin_transaction:" << error.get_msg().c_str(); + //FIXME we should somehow retry the transaction... + Q_ASSERT(false); + } } return db; } @@ -116,7 +144,14 @@ void FulltextIndex::remove(const QByteArray &key) if (!mDb) { return; } - writableDatabase()->delete_document(idTerm(key)); + try { + writableDatabase()->delete_document(idTerm(key)); + } + catch (const Xapian::Error &error) { + SinkError() << "Exception during Xapian delete_document:" << error.get_msg().c_str(); + //FIXME we should somehow retry the transaction... + Q_ASSERT(false); + } } QVector FulltextIndex::lookup(const QString &searchTerm) -- cgit v1.2.3