From b84edb641b33129004fdb655054a00ecc9894c3b Mon Sep 17 00:00:00 2001 From: Joel Wetzell Date: Sat, 22 Nov 2025 14:24:44 -0600 Subject: [PATCH] add error handling to routing --- router.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/router.go b/router.go index 47f52b5..4bf126c 100644 --- a/router.go +++ b/router.go @@ -8,6 +8,11 @@ import ( "sync" ) +type RoutingError struct { + Index int + Error error +} + type Router struct { contextCancel context.CancelFunc Context context.Context @@ -129,15 +134,24 @@ func (r *Router) Stop() { r.contextCancel() } -func (r *Router) HandleInput(sourceId string, payload any) { +func (r *Router) HandleInput(sourceId string, payload any) []RoutingError { + var routingErrors []RoutingError for routeIndex, route := range r.RouteInstances { if route.Input == sourceId { err := route.HandleInput(sourceId, payload) if err != nil { + if routingErrors == nil { + routingErrors = []RoutingError{} + } + routingErrors = append(routingErrors, RoutingError{ + Index: routeIndex, + Error: err, + }) slog.Error("router unable to route input", "route", routeIndex, "source", sourceId, "error", err) } } } + return routingErrors } func (r *Router) HandleOutput(destinationId string, payload any) error {