From c10a1166fba0a58f91aab8924259df04ca7115dc Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Mon, 16 Jun 2014 13:08:04 +0200 Subject: [PATCH] Catch Zorba exceptions --- src/metaproxy_filter_xquery.cpp | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/src/metaproxy_filter_xquery.cpp b/src/metaproxy_filter_xquery.cpp index c3d5d91..bd29487 100644 --- a/src/metaproxy_filter_xquery.cpp +++ b/src/metaproxy_filter_xquery.cpp @@ -102,10 +102,16 @@ bool yf::XQuery::convert_one_record(const char *input_buf, lItem = lZorba->getItemFactory()->createString(rec_content); lDynamicContext->setVariable(zorba_record_variable, lItem); - std::stringstream ss; - tQuery->execute(ss); - result = ss.str(); - return true; + try { + std::stringstream ss; + tQuery->execute(ss); + result = ss.str(); + return true; + } catch ( ZorbaException &e) { + std::string msg = e.what(); + yaz_log(YLOG_WARN, "XQuery execute failure: %s", msg.c_str()); + return false; + } } void yf::XQuery::process(Package &package) const @@ -366,14 +372,19 @@ void yf::XQuery::configure(const xmlNode * ptr, bool test_only, lQuery = lZorba->createQuery(); - size_t t = zorba_script.find_last_of('/'); - if (t != std::string::npos) - lQuery->setFileName(zorba_script.substr(0, t + 1)); - - std::unique_ptr qfile( - new std::ifstream(zorba_script.c_str())); - Zorba_CompilerHints lHints; - lQuery->compile(*qfile, lHints); + try { + size_t t = zorba_script.find_last_of('/'); + if (t != std::string::npos) + lQuery->setFileName(zorba_script.substr(0, t + 1)); + std::unique_ptr qfile( + new std::ifstream(zorba_script.c_str())); + Zorba_CompilerHints lHints; + lQuery->compile(*qfile, lHints); + } catch ( ZorbaException &e) { + std::string msg = "XQuery compile failure: "; + msg += e.what(); + throw mp::filter::FilterException(msg); + } } } -- 1.7.10.4