From 69c90012f523b102d8395a40f2227c328a1ab0a9 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 1 Jun 2022 10:39:40 +1200 Subject: [PATCH] Improve exception message for removing empty term The exception type is still InvalidArgumentError but the message is now "Empty termnames are invalid" instead of the old message "Term '' is not present in document, [...]". The code on git master already reports the new message. Reported by David Bremner. --- xapian-core/api/omdocument.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/xapian-core/api/omdocument.cc b/xapian-core/api/omdocument.cc index 62689deba..8664ec4cd 100644 --- a/xapian-core/api/omdocument.cc +++ b/xapian-core/api/omdocument.cc @@ -516,6 +516,8 @@ Xapian::Document::Internal::remove_posting(const string & tname, map::iterator i; i = terms.find(tname); if (i == terms.end() || i->second.is_deleted()) { + if (tname.empty()) + throw Xapian::InvalidArgumentError("Empty termnames are invalid"); throw Xapian::InvalidArgumentError("Term '" + tname + "' is not present in document, in " "Xapian::Document::Internal::remove_posting()"); @@ -535,6 +537,8 @@ Xapian::Document::Internal::remove_postings(const string& term, auto i = terms.find(term); if (i == terms.end() || i->second.is_deleted()) { + if (term.empty()) + throw Xapian::InvalidArgumentError("Empty termnames are invalid"); throw Xapian::InvalidArgumentError("Term '" + term + "' is not present in document, in " "Xapian::Document::Internal::remove_postings()"); @@ -561,6 +565,8 @@ Xapian::Document::Internal::remove_term(const string & tname) map::iterator i; i = terms.find(tname); if (i == terms.end() || i->second.is_deleted()) { + if (tname.empty()) + throw Xapian::InvalidArgumentError("Empty termnames are invalid"); throw Xapian::InvalidArgumentError("Term '" + tname + "' is not present in document, in " "Xapian::Document::Internal::remove_term()"); -- 2.11.4.GIT