Don't crash on regex errors.
continuous-integration/drone/push Build is passing Details

The error will be reported once for each initial thread.

Closes: #14
This commit is contained in:
tastytea 2021-06-24 13:13:49 +02:00
parent 18c3d8f58d
commit 822bff1955
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
1 changed files with 16 additions and 1 deletions

View File

@ -45,6 +45,8 @@
#include <thread>
#include <vector>
constexpr int EXIT_FATAL{2};
int main(int argc, char *argv[])
{
using namespace epubgrep;
@ -77,7 +79,7 @@ int main(int argc, char *argv[])
{ // Exceptions we can't recover from or ones we don't know.
LOG(log::sev::fatal)
<< e.what() << translate(" (while parsing options)");
return EXIT_FAILURE;
return EXIT_FATAL;
}
if (opts.debug)
@ -175,6 +177,11 @@ int main(int argc, char *argv[])
filepath);
return EXIT_FAILURE;
}
catch (const boost::regex_error &e)
{
LOG(log::sev::fatal) << e.what();
return EXIT_FATAL;
}
}
return EXIT_SUCCESS;
@ -219,6 +226,10 @@ int main(int argc, char *argv[])
DEBUGLOG << "Attempting to clean up threads";
futures_cleanup();
}
if (return_code == EXIT_FATAL)
{
break;
}
futurepool.emplace_back(
std::async(std::launch::async, search_file, filepath));
DEBUGLOG << "Launched new thread";
@ -233,6 +244,10 @@ int main(int argc, char *argv[])
}
DEBUGLOG << "Waiting for remaining threads to finish";
futures_cleanup(true);
if (return_code == EXIT_FATAL)
{
return EXIT_FATAL;
}
if (opts.json)
{