Chess: Slightly improve error propagation during startup

This commit is contained in:
Ben Wiederhake 2023-05-07 01:59:10 +02:00 committed by Jelle Raaijmakers
parent 0fe29a48ad
commit 449911c286
Notes: sideshowbarker 2024-07-18 02:47:59 +09:00
4 changed files with 14 additions and 15 deletions

View File

@ -55,7 +55,7 @@ void Engine::connect_to_engine_service()
close(rpipefds[1]);
auto infile = Core::File::adopt_fd(rpipefds[0], Core::File::OpenMode::Read).release_value_but_fixme_should_propagate_errors();
set_in(move(infile));
set_in(move(infile)).release_value_but_fixme_should_propagate_errors();
auto outfile = Core::File::adopt_fd(wpipefds[1], Core::File::OpenMode::Write).release_value_but_fixme_should_propagate_errors();
set_out(move(outfile));

View File

@ -12,14 +12,6 @@
namespace Chess::UCI {
Endpoint::Endpoint(NonnullOwnPtr<Core::File> in, NonnullOwnPtr<Core::File> out)
: m_in_fd(in->fd())
, m_in(Core::BufferedFile::create(move(in)).release_value_but_fixme_should_propagate_errors())
, m_out(move(out))
{
set_in_notifier();
}
void Endpoint::send_command(Command const& command)
{
auto command_string = command.to_string().release_value_but_fixme_should_propagate_errors();

View File

@ -41,17 +41,17 @@ public:
virtual void event(Core::Event&) override;
void set_in(NonnullOwnPtr<Core::File> in)
ErrorOr<void> set_in(NonnullOwnPtr<Core::File> in)
{
m_in_fd = in->fd();
m_in = Core::BufferedFile::create(move(in)).release_value_but_fixme_should_propagate_errors();
m_in = TRY(Core::BufferedFile::create(move(in)));
set_in_notifier();
return {};
}
void set_out(NonnullOwnPtr<Core::File> out) { m_out = move(out); }
protected:
Endpoint() = default;
Endpoint(NonnullOwnPtr<Core::File> in, NonnullOwnPtr<Core::File> out);
virtual void custom_event(Core::CustomEvent&) override;
private:

View File

@ -12,8 +12,15 @@
#include <LibChess/UCIEndpoint.h>
class ChessEngine : public Chess::UCI::Endpoint {
C_OBJECT(ChessEngine)
C_OBJECT_ABSTRACT(ChessEngine)
public:
static ErrorOr<NonnullRefPtr<ChessEngine>> try_create(NonnullOwnPtr<Core::File> in, NonnullOwnPtr<Core::File> out)
{
auto engine = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) ChessEngine()));
TRY(engine->set_in(move(in)));
engine->set_out(move(out));
return engine;
}
virtual ~ChessEngine() override = default;
virtual void handle_uci() override;
@ -26,8 +33,8 @@ public:
Function<void(int)> on_quit;
private:
ChessEngine(NonnullOwnPtr<Core::File> in, NonnullOwnPtr<Core::File> out)
: Endpoint(move(in), move(out))
ChessEngine()
: Endpoint()
{
on_command_read_error = [](auto command, auto error) {
outln("{}: '{}'", error, command);