mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-29 06:02:07 +03:00
IPCCompiler+LibIPC: Propagate IPC encoder errors
This propagates errors from user-defined encoders up to IPC::Connection. There, we currently just log the error, as we aren't in a position to propagate it further (i.e. we are inside a deferred invocation).
This commit is contained in:
parent
ab99ed5fba
commit
8b7b03b369
Notes:
sideshowbarker
2024-07-17 02:12:22 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/8b7b03b369 Pull-request: https://github.com/SerenityOS/serenity/pull/16770
@ -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<IPC::MessageBuffer> 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<IPC::MessageBuffer> handle(const IPC::Message& message) override
|
||||
virtual ErrorOr<OwnPtr<IPC::MessageBuffer>> 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<const Messages::@endpoint.name@::@message.pascal_name@&>(message);
|
||||
@handler_name@(@arguments@);
|
||||
auto response = Messages::@endpoint.name@::@message.response_type@ { };
|
||||
return make<IPC::MessageBuffer>(response.encode());)~~~");
|
||||
return make<IPC::MessageBuffer>(TRY(response.encode()));)~~~");
|
||||
} else {
|
||||
message_generator.appendln(R"~~~(
|
||||
[[maybe_unused]] auto& request = static_cast<const Messages::@endpoint.name@::@message.pascal_name@&>(message);
|
||||
auto response = @handler_name@(@arguments@);
|
||||
if (!response.valid())
|
||||
return {};
|
||||
return make<IPC::MessageBuffer>(response.encode());)~~~");
|
||||
return Error::from_string_literal("Failed to handle @endpoint.name@::@message.pascal_name@ message");
|
||||
return make<IPC::MessageBuffer>(TRY(response.encode()));)~~~");
|
||||
}
|
||||
} else {
|
||||
message_generator.appendln(R"~~~(
|
||||
[[maybe_unused]] auto& request = static_cast<const Messages::@endpoint.name@::@message.pascal_name@&>(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");
|
||||
}
|
||||
})~~~");
|
||||
|
||||
|
@ -49,7 +49,7 @@ Core::Stream::LocalSocket& ConnectionBase::fd_passing_socket()
|
||||
|
||||
ErrorOr<void> ConnectionBase::post_message(Message const& message)
|
||||
{
|
||||
return post_message(message.encode());
|
||||
return post_message(TRY(message.encode()));
|
||||
}
|
||||
|
||||
ErrorOr<void> 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<MessageBuffer> encode() const = 0;
|
||||
|
||||
protected:
|
||||
Message() = default;
|
||||
|
@ -25,7 +25,7 @@ public:
|
||||
|
||||
virtual u32 magic() const = 0;
|
||||
virtual DeprecatedString name() const = 0;
|
||||
virtual OwnPtr<MessageBuffer> handle(Message const&) = 0;
|
||||
virtual ErrorOr<OwnPtr<MessageBuffer>> handle(Message const&) = 0;
|
||||
|
||||
protected:
|
||||
Stub() = default;
|
||||
|
Loading…
Reference in New Issue
Block a user