Fix crashes when trying to open a file of unknown type. Increase robustness of error handling.

This commit is contained in:
Tomasz Sobczyk
2020-10-22 11:20:31 +02:00
committed by nodchip
parent 886467e09f
commit af138d1937
2 changed files with 18 additions and 5 deletions

View File

@@ -187,11 +187,25 @@ namespace Learner{
filenames.pop_front();
sfen_input_stream = open_sfen_input_file(filename);
std::cout << "open filename = " << filename << std::endl;
// in case the file is empty or was deleted.
if (!sfen_input_stream->eof())
return true;
if (sfen_input_stream == nullptr)
{
std::cout << "File does not exist: " << filename << '\n';
}
else
{
std::cout << "Opened file for reading: " << filename << '\n';
// in case the file is empty or was deleted.
if (sfen_input_stream->eof())
{
std::cout << "File empty, nothing to read.\n";
}
else
{
return true;
}
}
}
};

View File

@@ -191,7 +191,6 @@ namespace Learner {
else if (has_extension(filename, BinpackSfenInputStream::extension))
return std::make_unique<BinpackSfenInputStream>(filename);
assert(false);
return nullptr;
}