summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2021-08-05 14:28:29 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2021-08-05 14:28:29 -0400
commit5e16ed0eea2cae21badd525afa0d464700bb8647 (patch)
tree3761c5c22307fdb35d783185a981b979404d7577 /src
parent94d41cd67a1591fff01c17e3aece48e1f19d297b (diff)
downloadSMAPI-5e16ed0eea2cae21badd525afa0d464700bb8647.tar.gz
SMAPI-5e16ed0eea2cae21badd525afa0d464700bb8647.tar.bz2
SMAPI-5e16ed0eea2cae21badd525afa0d464700bb8647.zip
prevent weird null reference exception in error-handling
Diffstat (limited to 'src')
-rw-r--r--src/SMAPI.Internal/ExceptionExtensions.cs27
1 files changed, 17 insertions, 10 deletions
diff --git a/src/SMAPI.Internal/ExceptionExtensions.cs b/src/SMAPI.Internal/ExceptionExtensions.cs
index 5f1ee1fa..d8189048 100644
--- a/src/SMAPI.Internal/ExceptionExtensions.cs
+++ b/src/SMAPI.Internal/ExceptionExtensions.cs
@@ -13,19 +13,26 @@ namespace StardewModdingAPI.Internal
/// <param name="exception">The error to summarize.</param>
public static string GetLogSummary(this Exception exception)
{
- switch (exception)
+ try
{
- case TypeLoadException ex:
- return $"Failed loading type '{ex.TypeName}': {exception}";
+ switch (exception)
+ {
+ case TypeLoadException ex:
+ return $"Failed loading type '{ex.TypeName}': {exception}";
- case ReflectionTypeLoadException ex:
- string summary = ex.ToString();
- foreach (Exception childEx in ex.LoaderExceptions ?? new Exception[0])
- summary += $"\n\n{childEx?.GetLogSummary()}";
- return summary;
+ case ReflectionTypeLoadException ex:
+ string summary = ex.ToString();
+ foreach (Exception childEx in ex.LoaderExceptions ?? new Exception[0])
+ summary += $"\n\n{childEx?.GetLogSummary()}";
+ return summary;
- default:
- return exception.ToString();
+ default:
+ return exception?.ToString() ?? $"<null exception>\n{Environment.StackTrace}";
+ }
+ }
+ catch (Exception ex)
+ {
+ throw new InvalidOperationException($"Failed handling {exception?.GetType().FullName} (original message: {exception?.Message})", ex);
}
}