cluster/Backend: Add ProcessError()

Allow backends to pass errors to a strategy. Locally, these raise
Cluster::Backend::error() events that are logged to the reporter
as errors.
This commit is contained in:
Arne Welzel 2025-04-10 16:15:54 +02:00
parent fcc0f45c57
commit 3d3b7a0759
5 changed files with 69 additions and 4 deletions

View file

@ -112,12 +112,20 @@ public:
* When the backend is instantiated for a WebSocket client,
* local scripting layer should not raise events for the
* WebSocket client.
*
* @param h The event handler to use.
* @param args The event arguments.
*/
void ProcessLocalEvent(EventHandlerPtr h, zeek::Args args) { DoProcessLocalEvent(h, std::move(args)); }
/**
* Process an error.
*
* @param tag A stringified structured error tag not further specified.
* @param message A free form message with more context.
*/
void ProcessError(std::string_view tag, std::string_view message) { return DoProcessError(tag, message); };
private:
/**
* Hook method for implementing ProcessEvent().
@ -136,6 +144,14 @@ private:
* @param args The event arguments.
*/
virtual void DoProcessLocalEvent(EventHandlerPtr h, zeek::Args args) = 0;
/**
* Hook method for implementing ProcessError().
*
* @param tag A stringified structured error tag not further specified.
* @param message A free form message with more context.
*/
virtual void DoProcessError(std::string_view tag, std::string_view message) = 0;
};
/**
@ -145,6 +161,7 @@ class LocalEventHandlingStrategy : public EventHandlingStrategy {
private:
bool DoProcessEvent(std::string_view topic, Event e) override;
void DoProcessLocalEvent(EventHandlerPtr h, zeek::Args args) override;
void DoProcessError(std::string_view tag, std::string_view message) override;
};
/**
@ -322,6 +339,18 @@ protected:
*/
bool ProcessEvent(std::string_view topic, detail::Event e);
/**
* An error happened, pass it to the event handling strategy.
*
* Errors are not necessarily in response to a publish operation, but
* can also be raised when receiving messages. E.g. if received data
* couldn't be properly parsed.
*
* @param tag A stringified structured error tag not further specified.
* @param message A free form message with more context.
*/
void ProcessError(std::string_view tag, std::string_view message);
/**
* Process an incoming event message.
*/