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,20 +109,31 @@ int main(int argc, char *argv[])
}
opts.context = vm["context"].as<std::uint64_t>();
for (const auto &match : search::search(filepath, regex, opts))
try
{
cout << match.filepath;
if (!match.headline.empty())
for (const auto &match :
search::search(filepath, regex, opts))
{
cout << match.filepath;
if (!match.headline.empty())
{
cout << ", " << match.headline;
cout << ", " << match.headline;
}
if (!match.page.empty())
{
cout << ", page " << match.page;
}
cout << ": " << match.context.first << match.text
<< match.context.second << '\n';
}
if (!match.page.empty())
{
cout << ", page " << match.page;
}
cout << ": " << match.context.first << match.text
<< 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;
}
}
}