diff --git a/src/main.cpp b/src/main.cpp index 5d3014c..d4b205d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -45,6 +45,8 @@ #include #include +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) {