1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 16:07:46 +00:00

LibChess+ChessEngine: Don't crash on error when reading UCI commands

ChessEngine and the chess GUI will no longer crash on error while
reading UCI commands. ChessEngine will print a message to the standard
output, while the GUI will ignore unknown commands. Both will print
the error to the debug log if the UCI_DEBUG flag is enabled.

Trailing and preceding whitespace is now stripped from commands before
they are parsed. Commands which are just whitespace no longer produce
errors.
This commit is contained in:
Tim Ledbetter 2023-04-30 17:05:11 +01:00 committed by Sam Atkins
parent 25778d07e9
commit 56dde3df54
3 changed files with 41 additions and 23 deletions

View file

@ -1,5 +1,6 @@
/*
* Copyright (c) 2020, the SerenityOS developers.
* Copyright (c) 2023, Tim Ledbetter <timledbetter@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -25,10 +26,12 @@ public:
Function<void(int)> on_quit;
private:
ChessEngine() = default;
ChessEngine(NonnullRefPtr<Core::IODevice> in, NonnullRefPtr<Core::IODevice> out)
: Endpoint(in, out)
{
on_command_read_error = [](auto command, auto error) {
outln("{}: '{}'", error, command);
};
}
Chess::Board m_board;