From add7547b50e1bac64650ff00cca5939c74be8d63 Mon Sep 17 00:00:00 2001 From: GHXX Date: Sun, 27 Jun 2021 13:40:15 +0200 Subject: [PATCH] added exception sanitizing --- .../Actions/Settings/SettingsHandler.cs | 2 +- DataInterfaceConsole/Extensions.cs | 10 ++++++++++ DataInterfaceConsole/Program.cs | 4 ++-- 3 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 DataInterfaceConsole/Extensions.cs diff --git a/DataInterfaceConsole/Actions/Settings/SettingsHandler.cs b/DataInterfaceConsole/Actions/Settings/SettingsHandler.cs index 201ea9d..6a3b5a2 100644 --- a/DataInterfaceConsole/Actions/Settings/SettingsHandler.cs +++ b/DataInterfaceConsole/Actions/Settings/SettingsHandler.cs @@ -69,7 +69,7 @@ public void Tick() } catch (Exception ex) { - Console.WriteLine($"Error while ticking settings handler:\n{ex}"); + Console.WriteLine($"Error while ticking settings handler:\n{ex.ToSanitizedString()}"); } } } diff --git a/DataInterfaceConsole/Extensions.cs b/DataInterfaceConsole/Extensions.cs new file mode 100644 index 0000000..767dc81 --- /dev/null +++ b/DataInterfaceConsole/Extensions.cs @@ -0,0 +1,10 @@ +using System; +using System.Text.RegularExpressions; + +namespace DataInterfaceConsole +{ + internal static class Extensions + { + public static string ToSanitizedString(this Exception e) => Regex.Replace(e.ToString(), @"([A-z]:[\\\/]Users[\\\/])(.*?)([\\\/])", "$1USERNAME$3"); + } +} diff --git a/DataInterfaceConsole/Program.cs b/DataInterfaceConsole/Program.cs index 1ff7cfd..f9b1c0b 100644 --- a/DataInterfaceConsole/Program.cs +++ b/DataInterfaceConsole/Program.cs @@ -66,7 +66,7 @@ private void Run() } catch (DataInterfaceClosedException ex) { - Util.WriteColored($"Execution of the current action '{a.Name}' was aborted because the game closed or crashed: \n{ex}", ConsoleColor.Red); + Util.WriteColored($"Execution of the current action '{a.Name}' was aborted because the game closed or crashed: \n{ex.ToSanitizedString()}", ConsoleColor.Red); ConsoleNonBlocking.ClearInputLines(); } break; @@ -79,7 +79,7 @@ private void Run() } catch (DataInterfaceClosedException ex) { - Util.WriteColored($"Execution of the current action selection was aborted because the game closed or crashed: \n{ex}", ConsoleColor.Red); + Util.WriteColored($"Execution of the current action selection was aborted because the game closed or crashed: \n{ex.ToSanitizedString()}", ConsoleColor.Red); ConsoleNonBlocking.ClearInputLines(); } }