logging: Better error messages for invalid Log::delay() calls

Add a test for Log::delay() usage within filter policy hooks, too.
This commit is contained in:
Arne Welzel 2023-11-28 11:09:12 +01:00
parent 5e046eee58
commit e2ce929fa4
6 changed files with 29 additions and 7 deletions

View file

@ -1190,12 +1190,13 @@ bool Manager::WriteToFilters(const Manager::Stream* stream, zeek::RecordValPtr c
ValPtr Manager::Delay(const EnumValPtr& id, const RecordValPtr record, FuncPtr post_delay_cb) {
if ( active_writes.size() == 0 ) {
reporter->Error("invalid Log::delay() call: no active write context available");
reporter->Error("invalid Log::delay() call: outside of Log::log_stream_policy() hook");
return make_intrusive<detail::LogDelayTokenVal>();
}
const auto& active_write_ctx = active_writes.back();
if ( active_write_ctx.id != id || active_write_ctx.record != record ) {
reporter->Error("invalid Log::delay() call: active write mismatch");
reporter->Error("invalid Log::delay() call: argument mismatch with active Log::write()");
return make_intrusive<detail::LogDelayTokenVal>();
}