diff --git a/docs/release-notes.md b/docs/release-notes.md
index f330c6773..f619623f4 100644
--- a/docs/release-notes.md
+++ b/docs/release-notes.md
@@ -4,7 +4,8 @@
## Upcoming release
* For players:
* Added more progress updates in the log during startup.
- * Simplified common asset load error message.
+ * Simplified asset load error message.
+ * Simplified exception logs.
* Fixed crash loading mods with corrupted translation files.
* For mod authors:
diff --git a/src/SMAPI.Internal/ExceptionExtensions.cs b/src/SMAPI.Internal/ExceptionHelper.cs
similarity index 51%
rename from src/SMAPI.Internal/ExceptionExtensions.cs
rename to src/SMAPI.Internal/ExceptionHelper.cs
index d81890486..4bc55f95e 100644
--- a/src/SMAPI.Internal/ExceptionExtensions.cs
+++ b/src/SMAPI.Internal/ExceptionHelper.cs
@@ -1,10 +1,11 @@
using System;
using System.Reflection;
+using System.Text.RegularExpressions;
namespace StardewModdingAPI.Internal
{
/// Provides extension methods for handling exceptions.
- internal static class ExceptionExtensions
+ internal static class ExceptionHelper
{
/*********
** Public methods
@@ -15,20 +16,26 @@ public static string GetLogSummary(this Exception exception)
{
try
{
+ string message;
switch (exception)
{
case TypeLoadException ex:
- return $"Failed loading type '{ex.TypeName}': {exception}";
+ message = $"Failed loading type '{ex.TypeName}': {exception}";
+ break;
case ReflectionTypeLoadException ex:
string summary = ex.ToString();
foreach (Exception childEx in ex.LoaderExceptions ?? new Exception[0])
summary += $"\n\n{childEx?.GetLogSummary()}";
- return summary;
+ message = summary;
+ break;
default:
- return exception?.ToString() ?? $"\n{Environment.StackTrace}";
+ message = exception?.ToString() ?? $"\n{Environment.StackTrace}";
+ break;
}
+
+ return ExceptionHelper.SimplifyExtensionMessage(message);
}
catch (Exception ex)
{
@@ -44,5 +51,26 @@ public static Exception GetInnermostException(this Exception exception)
exception = exception.InnerException;
return exception;
}
+
+ /// Simplify common patterns in exception log messages that don't convey useful info.
+ /// The log message to simplify.
+ public static string SimplifyExtensionMessage(string message)
+ {
+ // remove namespace for core exception types
+ message = Regex.Replace(
+ message,
+ @"(?:StardewModdingAPI\.Framework\.Exceptions|Microsoft\.Xna\.Framework|System|System\.IO)\.([a-zA-Z]+Exception):",
+ "$1:"
+ );
+
+ // remove unneeded root build paths for SMAPI and Stardew Valley
+ message = message
+ .Replace(@"C:\source\_Stardew\SMAPI\src\", "")
+ .Replace(@"C:\GitlabRunner\builds\Gq5qA5P4\0\ConcernedApe\", "");
+
+ // remove placeholder info in Linux/macOS stack traces
+ return message
+ .Replace(@":0", "");
+ }
}
}
diff --git a/src/SMAPI.Internal/SMAPI.Internal.projitems b/src/SMAPI.Internal/SMAPI.Internal.projitems
index 0ee94a5b7..41d356c0b 100644
--- a/src/SMAPI.Internal/SMAPI.Internal.projitems
+++ b/src/SMAPI.Internal/SMAPI.Internal.projitems
@@ -14,6 +14,6 @@
-
+
\ No newline at end of file
diff --git a/src/SMAPI/Framework/Logging/LogManager.cs b/src/SMAPI/Framework/Logging/LogManager.cs
index 6fe44d980..f28761469 100644
--- a/src/SMAPI/Framework/Logging/LogManager.cs
+++ b/src/SMAPI/Framework/Logging/LogManager.cs
@@ -406,6 +406,10 @@ private void HandleConsoleMessage(IMonitor gameMonitor, string message)
}
}
+ // simplify exception messages
+ if (level == LogLevel.Error)
+ message = ExceptionHelper.SimplifyExtensionMessage(message);
+
// forward to monitor
gameMonitor.Log(message, level);
}