Skip to content

GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.

feat(domain): log all events and commands invoked through Bus

Lars4dd3877aaedf
diff --git a/LarsWM.Infrastructure/Bussing/Bus.cs b/LarsWM.Infrastructure/Bussing/Bus.cs
index 77e9d409..38d1ca0c 100644
--- a/LarsWM.Infrastructure/Bussing/Bus.cs
+++ b/LarsWM.Infrastructure/Bussing/Bus.cs
@@ -1,6 +1,7 @@
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
+using System.Diagnostics;
using System.Linq;
namespace LarsWM.Infrastructure.Bussing
@@ -31,9 +32,17 @@ namespace LarsWM.Infrastructure.Bussing
throw new Exception("Only one CommandHandler can be registered to handle a Command.");
}
- // TODO: Add centralised error handling here?
- ICommandHandler<T> handlerInstance = ServiceLocator.Provider.GetRequiredService(handlers[0]) as ICommandHandler<T>;
- return handlerInstance.Handle(command);
+ try
+ {
+ Debug.WriteLine($"Command {command.Name} invoked.");
+ ICommandHandler<T> handlerInstance = ServiceLocator.Provider.GetRequiredService(handlers[0]) as ICommandHandler<T>;
+ return handlerInstance.Handle(command);
+ }
+ catch (Exception exception)
+ {
+ // TODO: Add centralised error handling here?
+ throw exception;
+ }
}
/// <summary>
@@ -49,10 +58,19 @@ namespace LarsWM.Infrastructure.Bussing
var handlersToCall = _registeredEventHandlers.Where(handler => handlerTypeToCall.IsAssignableFrom(handler));
- foreach (var handler in handlersToCall)
+ try
+ {
+ Debug.WriteLine($"Event {@event.Name} emitted.");
+ foreach (var handler in handlersToCall)
+ {
+ IEventHandler<T> handlerInstance = ServiceLocator.Provider.GetService(handler) as IEventHandler<T>;
+ handlerInstance.Handle(@event);
+ }
+ }
+ catch (Exception exception)
{
- IEventHandler<T> handlerInstance = ServiceLocator.Provider.GetService(handler) as IEventHandler<T>;
- handlerInstance.Handle(@event);
+ // TODO: Add centralised error handling here?
+ throw exception;
}
}