Add basic error handling to search.

This commit is contained in:
tastytea 2021-05-24 19:10:00 +02:00
parent 21dccbbb12
commit 1f25daed26
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
1 changed files with 21 additions and 10 deletions

View File

@ -109,7 +109,10 @@ int main(int argc, char *argv[])
}
opts.context = vm["context"].as<std::uint64_t>();
for (const auto &match : search::search(filepath, regex, opts))
try
{
for (const auto &match :
search::search(filepath, regex, opts))
{
cout << match.filepath;
if (!match.headline.empty())
@ -125,6 +128,14 @@ int main(int argc, char *argv[])
<< match.context.second << '\n';
}
}
catch (const std::exception &e)
{ // Unknown errors.
cerr << '\n' << translate("ERROR: ") << e.what() << '\n';
cerr << translate("Error while searching.") << '\n';
// NOTE: Maybe we should continue with the next regex/file?
return EXIT_FAILURE;
}
}
}
}
}