add error handling to routing

This commit is contained in:
Joel Wetzell
2025-11-22 14:24:44 -06:00
parent 92f36d69f7
commit b84edb641b

View File

@@ -8,6 +8,11 @@ import (
"sync" "sync"
) )
type RoutingError struct {
Index int
Error error
}
type Router struct { type Router struct {
contextCancel context.CancelFunc contextCancel context.CancelFunc
Context context.Context Context context.Context
@@ -129,15 +134,24 @@ func (r *Router) Stop() {
r.contextCancel() 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 { for routeIndex, route := range r.RouteInstances {
if route.Input == sourceId { if route.Input == sourceId {
err := route.HandleInput(sourceId, payload) err := route.HandleInput(sourceId, payload)
if err != nil { 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) slog.Error("router unable to route input", "route", routeIndex, "source", sourceId, "error", err)
} }
} }
} }
return routingErrors
} }
func (r *Router) HandleOutput(destinationId string, payload any) error { func (r *Router) HandleOutput(destinationId string, payload any) error {