From 9f7e851263b96acacc9ea542e9f5d837563fea05 Mon Sep 17 00:00:00 2001 From: Luis Ressel Date: Mon, 11 Mar 2019 18:14:49 +0100 Subject: [PATCH] Prepend regerror() messages with "regexp error: " The exact error messages returned by regerror() aren't standardized; relying on them isn't portable. Thus, add a a prefix to make clear that the subsequent message is a regexp parsing error, and only look for this prefix in the test suite, ignoring the rest of the message. --- lib/regexp-fields.cc | 4 ++-- test/T650-regexp-query.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/regexp-fields.cc b/lib/regexp-fields.cc index 084bc8c0..f50da9a3 100644 --- a/lib/regexp-fields.cc +++ b/lib/regexp-fields.cc @@ -35,9 +35,9 @@ compile_regex (regex_t ®exp, const char *str) if (err != 0) { size_t len = regerror (err, ®exp, NULL, 0); char *buffer = new char[len]; - std::string msg; + std::string msg = "Regexp error: "; (void) regerror (err, ®exp, buffer, len); - msg.assign (buffer, len); + msg.append (buffer, len); delete[] buffer; throw Xapian::QueryParserError (msg); diff --git a/test/T650-regexp-query.sh b/test/T650-regexp-query.sh index 4085340f..31b3d036 100755 --- a/test/T650-regexp-query.sh +++ b/test/T650-regexp-query.sh @@ -137,10 +137,10 @@ EOF test_expect_equal_file EXPECTED OUTPUT test_begin_subtest "regexp error reporting" -notmuch search 'from:/unbalanced[/' 1>OUTPUT 2>&1 +notmuch search 'from:/unbalanced[/' 2>&1 | sed -e '/^A Xapian/ s/[^:]*$//' > OUTPUT cat < EXPECTED notmuch search: A Xapian exception occurred -A Xapian exception occurred parsing query: Invalid regular expression +A Xapian exception occurred parsing query: Regexp error: Query string was: from:/unbalanced[/ EOF test_expect_equal_file EXPECTED OUTPUT