mirror of
https://github.com/HChaZZY/Stockfish.git
synced 2025-12-24 19:16:49 +08:00
Fix crashes when trying to open a file of unknown type. Increase robustness of error handling.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -191,7 +191,6 @@ namespace Learner {
|
||||
else if (has_extension(filename, BinpackSfenInputStream::extension))
|
||||
return std::make_unique<BinpackSfenInputStream>(filename);
|
||||
|
||||
assert(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user