Don't crash if language detection fails.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
If there is no container.xml or something unexpected happens, we just return an empty string.
This commit is contained in:
parent
1e0cde8a4b
commit
552df1a49e
15
src/book.cpp
15
src/book.cpp
|
@ -57,6 +57,8 @@ book read(const fs::path filepath, const bool raw)
|
|||
|
||||
book current_book;
|
||||
current_book.language = [&filepath]() -> string
|
||||
{
|
||||
try
|
||||
{
|
||||
pugi::xml_document xml;
|
||||
auto opf_file_path{get_opf_file_path(filepath)};
|
||||
|
@ -66,8 +68,9 @@ book read(const fs::path filepath, const bool raw)
|
|||
const auto result{xml.load_buffer(&opf_file[0], opf_file.size())};
|
||||
if (result)
|
||||
{
|
||||
auto lang{
|
||||
xml.child("package").child("metadata").child("dc:language")};
|
||||
auto lang{xml.child("package")
|
||||
.child("metadata")
|
||||
.child("dc:language")};
|
||||
if (lang == nullptr)
|
||||
{
|
||||
lang = xml.child("opf:package")
|
||||
|
@ -76,6 +79,14 @@ book read(const fs::path filepath, const bool raw)
|
|||
}
|
||||
return lang.text().as_string();
|
||||
}
|
||||
}
|
||||
catch (epubgrep::zip::exception &e)
|
||||
{
|
||||
if (e.code != 1) // 1 == container.xml not found.
|
||||
{
|
||||
LOG(log::sev::error) << e.what();
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}();
|
||||
DEBUGLOG << "Book language detected: " << current_book.language;
|
||||
|
|
Loading…
Reference in New Issue
Block a user