diff --git a/Meta/Lagom/Tools/CodeGenerators/IPCCompiler/main.cpp b/Meta/Lagom/Tools/CodeGenerators/IPCCompiler/main.cpp index 5c6dabe4f70..b919e97acbd 100644 --- a/Meta/Lagom/Tools/CodeGenerators/IPCCompiler/main.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/IPCCompiler/main.cpp @@ -395,21 +395,21 @@ public:)~~~"); message_generator.appendln(R"~~~( virtual bool valid() const override { return m_ipc_message_valid; } - virtual IPC::MessageBuffer encode() const override + virtual ErrorOr encode() const override { VERIFY(valid()); IPC::MessageBuffer buffer; IPC::Encoder stream(buffer); - stream << endpoint_magic(); - stream << (int)MessageID::@message.pascal_name@;)~~~"); + TRY(stream.encode(endpoint_magic())); + TRY(stream.encode((int)MessageID::@message.pascal_name@));)~~~"); for (auto const& parameter : parameters) { auto parameter_generator = message_generator.fork(); parameter_generator.set("parameter.name", parameter.name); parameter_generator.appendln(R"~~~( - stream << m_@parameter.name@;)~~~"); + TRY(stream.encode(m_@parameter.name@));)~~~"); } message_generator.appendln(R"~~~( @@ -665,7 +665,7 @@ public: virtual u32 magic() const override { return @endpoint.magic@; } virtual DeprecatedString name() const override { return "@endpoint.name@"; } - virtual OwnPtr handle(const IPC::Message& message) override + virtual ErrorOr> handle(const IPC::Message& message) override { switch (message.message_id()) {)~~~"); for (auto const& message : endpoint.messages) { @@ -694,20 +694,20 @@ public: [[maybe_unused]] auto& request = static_cast(message); @handler_name@(@arguments@); auto response = Messages::@endpoint.name@::@message.response_type@ { }; - return make(response.encode());)~~~"); + return make(TRY(response.encode()));)~~~"); } else { message_generator.appendln(R"~~~( [[maybe_unused]] auto& request = static_cast(message); auto response = @handler_name@(@arguments@); if (!response.valid()) - return {}; - return make(response.encode());)~~~"); + return Error::from_string_literal("Failed to handle @endpoint.name@::@message.pascal_name@ message"); + return make(TRY(response.encode()));)~~~"); } } else { message_generator.appendln(R"~~~( [[maybe_unused]] auto& request = static_cast(message); @handler_name@(@arguments@); - return {};)~~~"); + return nullptr;)~~~"); } message_generator.appendln(R"~~~( })~~~"); @@ -716,7 +716,7 @@ public: } generator.appendln(R"~~~( default: - return {}; + return Error::from_string_literal("Unknown message ID for @endpoint.name@ endpoint"); } })~~~"); diff --git a/Userland/Libraries/LibIPC/Connection.cpp b/Userland/Libraries/LibIPC/Connection.cpp index e6247d264c9..ab36d6bc983 100644 --- a/Userland/Libraries/LibIPC/Connection.cpp +++ b/Userland/Libraries/LibIPC/Connection.cpp @@ -49,7 +49,7 @@ Core::Stream::LocalSocket& ConnectionBase::fd_passing_socket() ErrorOr ConnectionBase::post_message(Message const& message) { - return post_message(message.encode()); + return post_message(TRY(message.encode())); } ErrorOr ConnectionBase::post_message(MessageBuffer buffer) @@ -129,9 +129,15 @@ void ConnectionBase::handle_messages() auto messages = move(m_unprocessed_messages); for (auto& message : messages) { if (message.endpoint_magic() == m_local_endpoint_magic) { - if (auto response = m_local_stub.handle(message)) { - if (auto result = post_message(*response); result.is_error()) { - dbgln("IPC::ConnectionBase::handle_messages: {}", result.error()); + auto handler_result = m_local_stub.handle(message); + if (handler_result.is_error()) { + dbgln("IPC::ConnectionBase::handle_messages: {}", handler_result.error()); + continue; + } + + if (auto response = handler_result.release_value()) { + if (auto post_result = post_message(*response); post_result.is_error()) { + dbgln("IPC::ConnectionBase::handle_messages: {}", post_result.error()); } } } diff --git a/Userland/Libraries/LibIPC/Message.h b/Userland/Libraries/LibIPC/Message.h index 4690b1d5050..a5f202ec0ef 100644 --- a/Userland/Libraries/LibIPC/Message.h +++ b/Userland/Libraries/LibIPC/Message.h @@ -54,7 +54,7 @@ public: virtual int message_id() const = 0; virtual char const* message_name() const = 0; virtual bool valid() const = 0; - virtual MessageBuffer encode() const = 0; + virtual ErrorOr encode() const = 0; protected: Message() = default; diff --git a/Userland/Libraries/LibIPC/Stub.h b/Userland/Libraries/LibIPC/Stub.h index 5e34016e450..b64afa824ce 100644 --- a/Userland/Libraries/LibIPC/Stub.h +++ b/Userland/Libraries/LibIPC/Stub.h @@ -25,7 +25,7 @@ public: virtual u32 magic() const = 0; virtual DeprecatedString name() const = 0; - virtual OwnPtr handle(Message const&) = 0; + virtual ErrorOr> handle(Message const&) = 0; protected: Stub() = default;