From 16e413799363871c1efd73527fba299dfdfadfd3 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Wed, 13 May 2026 19:42:30 +0300 Subject: refactor: extract outputFormatter collaborator from eventLoop MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The printCb and warningCb function fields on eventLoop bundled two distinct concerns (pair emission and warning delivery) directly on the event-processing struct. This commit extracts them into a dedicated outputFormatter type that owns these callbacks plus emit() and notifyWarning() helper methods. outputFormatter is embedded (not pointed-to) in eventLoop so that existing call sites — including tests that write el.printCb = ... and el.warningCb = ... directly — require no changes beyond the three struct-literal sites in eventloop_filter_test.go that used field initialiser syntax. fdTracker and commResolver were already proper collaborator types; only the output concern needed extraction. Co-Authored-By: Claude Sonnet 4.6 --- internal/eventloop_exit.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'internal/eventloop_exit.go') diff --git a/internal/eventloop_exit.go b/internal/eventloop_exit.go index 5f6442c..e4ae6eb 100644 --- a/internal/eventloop_exit.go +++ b/internal/eventloop_exit.go @@ -291,18 +291,16 @@ func (e *eventLoop) registerDup(fdFile *file.FdFile, newFd int32, extraFlags int e.fdState().set(newFd, duppedFdFile) } +// recyclePair notifies about the problem described by warning, then returns ep +// to the pool. It is a convenience helper used throughout the exit handlers to +// keep the error path concise. func (e *eventLoop) recyclePair(ep *event.Pair, warning string) { e.notifyWarning(warning) ep.Recycle() } -func (e *eventLoop) notifyWarning(message string) { - if e.warningCb == nil || message == "" { - return - } - e.warningCb(message) -} - +// dropMalformedRawEvent records a warning when a raw BPF event cannot be +// decoded, keeping the error visible without crashing the event loop. func (e *eventLoop) dropMalformedRawEvent(evType types.EventType, raw []byte) { e.notifyWarning(fmt.Sprintf("Dropped malformed raw event type %d (len=%d)", evType, len(raw))) } -- cgit v1.2.3