Reformat error messages.

One line per error message.
This commit is contained in:
tastytea 2021-05-29 12:42:29 +02:00
parent 26678812c9
commit c94d9de0db
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
2 changed files with 28 additions and 16 deletions

View File

@ -32,12 +32,14 @@
#include <cstdint>
#include <cstdlib>
#include <exception>
#include <fstream>
#include <future>
#include <iostream>
#include <locale>
#include <mutex>
#include <string>
#include <string_view>
#include <system_error>
#include <thread>
#include <vector>
@ -70,8 +72,8 @@ int main(int argc, char *argv[])
}
catch (std::exception &e)
{ // Exceptions we can't recover from or ones we don't know.
cerr << translate("ERROR: ") << e.what() << '\n';
cerr << translate("Error while parsing options.") << '\n';
cerr << translate("ERROR: ") << e.what();
cerr << translate(" (while parsing options)") << '\n';
return EXIT_FAILURE;
}
@ -150,17 +152,33 @@ int main(int argc, char *argv[])
catch (const zip::exception &e)
{
if (opts.ignore_archive_errors && e.code == 1)
{
{ // File is probably not an EPUB.
return EXIT_SUCCESS;
}
cerr << translate("ERROR: ") << e.what() << '\n';
cerr << format(translate("Error while searching {0:s}.")
.str(),
cerr << translate("ERROR: ") << e.what();
cerr << format(translate(" (while searching {0:s})").str(),
filepath)
<< '\n';
return EXIT_FAILURE;
}
catch (const std::ifstream::failure &e)
{
cerr << translate("ERROR: ");
if (e.code() == std::errc::permission_denied)
{
cerr << translate("Permission denied.");
}
else
{ // std::ifstream seems to always return a generic error?
cerr << translate("Probably permission denied.") << " ("
<< e.what() << ')';
}
cerr << format(translate(" (while opening {0:s})").str(),
filepath)
<< '\n';
}
}
return EXIT_SUCCESS;

View File

@ -106,16 +106,10 @@ std::string read_file(const fs::path &filepath, std::string_view entry_path)
struct archive *open_file(const fs::path &filepath)
{
std::ifstream file{filepath};
if (!file.good())
{
exception e{format(translate("Could not open {0:s}: "
"Permission denied.")
.str(),
filepath.string())};
e.code = 2;
throw exception{e};
}
// Throw exception if we can't open the file.
std::ifstream file;
file.exceptions(std::ios::failbit);
file.open(filepath);
file.close();
auto *zipfile{archive_read_new()};