Kaydet (Commit) 4c912d3d authored tarafından Caolán McNamara's avatar Caolán McNamara

Resolves: fdo#51572 catch CLuceneError throws and extract the error message

I can't reproduce fdo#51572, but catching the exception in
HelpIndexer::indexDocuments should resolve it anyway and make it non-fatal.
Collect the error message for retrieval via HelpIndexer::getErrorMessage

Change-Id: Id557b9f5ff968c398f76969591f5ee765e56aa5a
üst 4fc8af89
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
#include <rtl/ustrbuf.hxx> #include <rtl/ustrbuf.hxx>
#include <osl/file.hxx> #include <osl/file.hxx>
#include <osl/thread.h> #include <osl/thread.h>
#include <boost/scoped_ptr.hpp>
#include <algorithm> #include <algorithm>
#include "LuceneHelper.hxx" #include "LuceneHelper.hxx"
...@@ -51,26 +51,28 @@ HelpIndexer::HelpIndexer(rtl::OUString const &lang, rtl::OUString const &module, ...@@ -51,26 +51,28 @@ HelpIndexer::HelpIndexer(rtl::OUString const &lang, rtl::OUString const &module,
d_contentDir = srcDir + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/content")); d_contentDir = srcDir + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/content"));
} }
bool HelpIndexer::indexDocuments() { bool HelpIndexer::indexDocuments()
if (!scanForFiles()) { {
if (!scanForFiles())
return false; return false;
}
try
{
rtl::OUString sLang = d_lang.getToken(0, '-'); rtl::OUString sLang = d_lang.getToken(0, '-');
bool bUseCJK = sLang == "ja" || sLang == "ko" || sLang == "zh"; bool bUseCJK = sLang == "ja" || sLang == "ko" || sLang == "zh";
// Construct the analyzer appropriate for the given language // Construct the analyzer appropriate for the given language
lucene::analysis::Analyzer *analyzer; boost::scoped_ptr<lucene::analysis::Analyzer> analyzer;
if (bUseCJK) if (bUseCJK)
analyzer = new lucene::analysis::LanguageBasedAnalyzer(L"cjk"); analyzer.reset(new lucene::analysis::LanguageBasedAnalyzer(L"cjk"));
else else
analyzer = new lucene::analysis::standard::StandardAnalyzer(); analyzer.reset(new lucene::analysis::standard::StandardAnalyzer());
rtl::OUString ustrSystemPath; rtl::OUString ustrSystemPath;
osl::File::getSystemPathFromFileURL(d_indexDir, ustrSystemPath); osl::File::getSystemPathFromFileURL(d_indexDir, ustrSystemPath);
rtl::OString indexDirStr = rtl::OUStringToOString(ustrSystemPath, osl_getThreadTextEncoding()); rtl::OString indexDirStr = rtl::OUStringToOString(ustrSystemPath, osl_getThreadTextEncoding());
lucene::index::IndexWriter writer(indexDirStr.getStr(), analyzer, true); lucene::index::IndexWriter writer(indexDirStr.getStr(), analyzer.get(), true);
//Double limit of tokens allowed, otherwise we'll get a too-many-tokens //Double limit of tokens allowed, otherwise we'll get a too-many-tokens
//exception for ja help. Could alternative ignore the exception and get //exception for ja help. Could alternative ignore the exception and get
//truncated results as per java-Lucene apparently //truncated results as per java-Lucene apparently
...@@ -87,8 +89,13 @@ bool HelpIndexer::indexDocuments() { ...@@ -87,8 +89,13 @@ bool HelpIndexer::indexDocuments() {
// Optimize the index // Optimize the index
writer.optimize(); writer.optimize();
}
catch (CLuceneError &e)
{
d_error = rtl::OUString::createFromAscii(e.what());
return false;
}
delete analyzer;
return true; return true;
} }
......
...@@ -99,18 +99,10 @@ int main(int argc, char **argv) { ...@@ -99,18 +99,10 @@ int main(int argc, char **argv) {
rtl::OUString(module.c_str(), module.size(), osl_getThreadTextEncoding()), rtl::OUString(module.c_str(), module.size(), osl_getThreadTextEncoding()),
sDir, sDir); sDir, sDir);
try
{
if (!indexer.indexDocuments()) { if (!indexer.indexDocuments()) {
std::cerr << rtl::OUStringToOString(indexer.getErrorMessage(), osl_getThreadTextEncoding()).getStr() << std::endl; std::cerr << rtl::OUStringToOString(indexer.getErrorMessage(), osl_getThreadTextEncoding()).getStr() << std::endl;
return 2; return 2;
} }
}
catch (CLuceneError &e)
{
std::cerr << e.what() << std::endl;
return 2;
}
return 0; return 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment