diff options
author | Ben Wiederhake <BenWiederhake.GitHub@gmx.de> | 2023-05-07 01:59:10 +0200 |
---|---|---|
committer | Jelle Raaijmakers <jelle@gmta.nl> | 2023-05-07 14:04:55 +0200 |
commit | 449911c28661a836d5ebdecef014cc4e122fd3f1 (patch) | |
tree | 8c023fc75893152a999bda65ae3ebe085c584c2e /Userland | |
parent | 0fe29a48ad85ed592b81b77cdd51a0cddbce6c44 (diff) | |
download | serenity-449911c28661a836d5ebdecef014cc4e122fd3f1.zip |
Chess: Slightly improve error propagation during startup
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Games/Chess/Engine.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibChess/UCIEndpoint.cpp | 8 | ||||
-rw-r--r-- | Userland/Libraries/LibChess/UCIEndpoint.h | 6 | ||||
-rw-r--r-- | Userland/Services/ChessEngine/ChessEngine.h | 13 |
4 files changed, 14 insertions, 15 deletions
diff --git a/Userland/Games/Chess/Engine.cpp b/Userland/Games/Chess/Engine.cpp index b70b83169d..cfe7502482 100644 --- a/Userland/Games/Chess/Engine.cpp +++ b/Userland/Games/Chess/Engine.cpp @@ -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)); diff --git a/Userland/Libraries/LibChess/UCIEndpoint.cpp b/Userland/Libraries/LibChess/UCIEndpoint.cpp index 52ac7f74fa..a137124adb 100644 --- a/Userland/Libraries/LibChess/UCIEndpoint.cpp +++ b/Userland/Libraries/LibChess/UCIEndpoint.cpp @@ -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(); diff --git a/Userland/Libraries/LibChess/UCIEndpoint.h b/Userland/Libraries/LibChess/UCIEndpoint.h index f23bf89385..8c2104162b 100644 --- a/Userland/Libraries/LibChess/UCIEndpoint.h +++ b/Userland/Libraries/LibChess/UCIEndpoint.h @@ -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: diff --git a/Userland/Services/ChessEngine/ChessEngine.h b/Userland/Services/ChessEngine/ChessEngine.h index 4a95d47c26..69c20fae9e 100644 --- a/Userland/Services/ChessEngine/ChessEngine.h +++ b/Userland/Services/ChessEngine/ChessEngine.h @@ -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); |