summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI/Framework/InternalExtensions.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/StardewModdingAPI/Framework/InternalExtensions.cs')
-rw-r--r--src/StardewModdingAPI/Framework/InternalExtensions.cs33
1 files changed, 20 insertions, 13 deletions
diff --git a/src/StardewModdingAPI/Framework/InternalExtensions.cs b/src/StardewModdingAPI/Framework/InternalExtensions.cs
index a2d589ff..5199c72d 100644
--- a/src/StardewModdingAPI/Framework/InternalExtensions.cs
+++ b/src/StardewModdingAPI/Framework/InternalExtensions.cs
@@ -41,6 +41,14 @@ namespace StardewModdingAPI.Framework
foreach (EventHandler handler in handlers.Cast<EventHandler>())
{
+ // handle SMAPI exiting
+ if (monitor.IsExiting)
+ {
+ monitor.Log($"SMAPI shutting down: aborting {name} event.", LogLevel.Warn);
+ return;
+ }
+
+ // raise event
try
{
handler.Invoke(sender, args ?? EventArgs.Empty);
@@ -84,21 +92,20 @@ namespace StardewModdingAPI.Framework
/// <param name="exception">The error to summarise.</param>
public static string GetLogSummary(this Exception exception)
{
- // type load exception
- if (exception is TypeLoadException typeLoadEx)
- return $"Failed loading type: {typeLoadEx.TypeName}: {exception}";
-
- // reflection type load exception
- if (exception is ReflectionTypeLoadException reflectionTypeLoadEx)
+ switch (exception)
{
- string summary = exception.ToString();
- foreach (Exception childEx in reflectionTypeLoadEx.LoaderExceptions)
- summary += $"\n\n{childEx.GetLogSummary()}";
- return summary;
- }
+ case TypeLoadException ex:
+ return $"Failed loading type '{ex.TypeName}': {exception}";
+
+ case ReflectionTypeLoadException ex:
+ string summary = exception.ToString();
+ foreach (Exception childEx in ex.LoaderExceptions)
+ summary += $"\n\n{childEx.GetLogSummary()}";
+ return summary;
- // anything else
- return exception.ToString();
+ default:
+ return exception.ToString();
+ }
}
/****