Add basic error handling to search.
This commit is contained in:
parent
21dccbbb12
commit
1f25daed26
31
src/main.cpp
31
src/main.cpp
@ -109,20 +109,31 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
opts.context = vm["context"].as<std::uint64_t>();
|
opts.context = vm["context"].as<std::uint64_t>();
|
||||||
|
|
||||||
for (const auto &match : search::search(filepath, regex, opts))
|
try
|
||||||
{
|
{
|
||||||
cout << match.filepath;
|
for (const auto &match :
|
||||||
if (!match.headline.empty())
|
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())
|
}
|
||||||
{
|
catch (const std::exception &e)
|
||||||
cout << ", page " << match.page;
|
{ // Unknown errors.
|
||||||
}
|
cerr << '\n' << translate("ERROR: ") << e.what() << '\n';
|
||||||
cout << ": " << match.context.first << match.text
|
cerr << translate("Error while searching.") << '\n';
|
||||||
<< match.context.second << '\n';
|
// NOTE: Maybe we should continue with the next regex/file?
|
||||||
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user