Browse Source

Fix error handling when instantiating `std::regex`

lmdb
Martchus 3 months ago
parent
commit
d006c9ce4f
2 changed files with 11 additions and 2 deletions
  1. +5
    -1
      librepomgr/webapi/routes.cpp
  2. +6
    -1
      pacfind/main.cpp

+ 5
- 1
librepomgr/webapi/routes.cpp View File

@ -273,7 +273,11 @@ void getPackages(const Params &params, ResponseHandler &&handler)
break;
case Mode::Regex:
// assume names are regexes
pushPackages(params.setup.config.findPackages(std::regex(name.data(), name.size())));
try {
pushPackages(params.setup.config.findPackages(std::regex(name.data(), name.size())));
} catch (const std::regex_error &e) {
throw BadRequest(argsToString("regex is invalid: ", e.what()));
}
break;
case Mode::Provides:
case Mode::Depends:


+ 6
- 1
pacfind/main.cpp View File

@ -112,7 +112,12 @@ int main(int argc, const char *argv[])
const auto negate = negateArg.isPresent();
auto regex = std::optional<std::regex>();
if (regexArg.isPresent()) {
regex = std::regex(searchTerm, std::regex::egrep);
try {
regex = std::regex(searchTerm, std::regex::egrep);
} catch (const std::regex_error &e) {
cerr << "Specified regex is invalid: " << e.what() << endl;
exit(3);
}
}
for (const Database &db : cfg.databases) {
for (const auto &pkg : db.packages) {


Loading…
Cancel
Save