GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
feat(domain): show error dialog on any `FatalUserException`s
Lars Berger3c44cef37084
diff --git a/LarsWM.Domain/UserConfigs/CommandHandlers/EvaluateUserConfigHandler.cs b/LarsWM.Domain/UserConfigs/CommandHandlers/EvaluateUserConfigHandler.csindex 1652e377..3921d770 100644--- a/LarsWM.Domain/UserConfigs/CommandHandlers/EvaluateUserConfigHandler.cs+++ b/LarsWM.Domain/UserConfigs/CommandHandlers/EvaluateUserConfigHandler.cs@@ -5,7 +5,6 @@ using LarsWM.Infrastructure.WindowsApi;using System;using System.IO;using System.Text.RegularExpressions;-using System.Windows;using YamlDotNet.Serialization;using YamlDotNet.Serialization.NamingConventions;using YamlDotNet.Serialization.NodeDeserializers;@@ -44,8 +43,8 @@ namespace LarsWM.Domain.UserConfigs.CommandHandlers}catch (Exception exception){- ShowErrorAlert(exception);- throw exception;+ var errorMessage = FormatErrorMessage(exception);+ throw new FatalUserException(errorMessage);}// Create an inactive `Workspace` for each workspace config.@@ -76,7 +75,7 @@ namespace LarsWM.Domain.UserConfigs.CommandHandlersreturn deserializer.Deserialize<UserConfig>(input);}- private void ShowErrorAlert(Exception exception)+ private string FormatErrorMessage(Exception exception){var errorMessage = exception.Message;@@ -92,8 +91,7 @@ namespace LarsWM.Domain.UserConfigs.CommandHandlerserrorMessage += $". {exception.InnerException.Message}";}- // Alert the user of the config error.- MessageBox.Show(errorMessage);+ return errorMessage;}}}diff --git a/LarsWM.Infrastructure/Bussing/Bus.cs b/LarsWM.Infrastructure/Bussing/Bus.csindex 6d879443..51c717f1 100644--- a/LarsWM.Infrastructure/Bussing/Bus.cs+++ b/LarsWM.Infrastructure/Bussing/Bus.cs@@ -4,6 +4,7 @@ using System.Collections.Generic;using System.Diagnostics;using System.IO;using System.Reactive.Subjects;+using System.Windows;namespace LarsWM.Infrastructure.Bussing{@@ -35,7 +36,12 @@ namespace LarsWM.Infrastructure.Bussing}catch (Exception error){- File.AppendAllText("./errors.log", error.Message + error.StackTrace);+ // Alert the user of the error.+ // TODO: This throws duplicate errors if a command errors and it was invoked by another handler.+ if (error is FatalUserException)+ MessageBox.Show(error.Message);++ File.AppendAllText("./errors.log", $"\n\n{error.Message + error.StackTrace}");throw error;}}@@ -67,7 +73,11 @@ namespace LarsWM.Infrastructure.Bussing}catch (Exception error){- File.AppendAllText("./errors.log", error.Message + error.StackTrace);+ // Alert the user of the error.+ if (error is FatalUserException)+ MessageBox.Show(error.Message);++ File.AppendAllText("./errors.log", $"\n\n{error.Message + error.StackTrace}");throw error;}}