prevent weird null reference exception in error-handling

This commit is contained in:
Jesse Plamondon-Willard 2021-08-05 14:28:29 -04:00
parent 94d41cd67a
commit 5e16ed0eea
No known key found for this signature in database
GPG Key ID: CF8B1456B3E29F49
2 changed files with 21 additions and 10 deletions

View File

@ -1,6 +1,10 @@
← [README](README.md)
# Release notes
## Upcoming release
* For mod authors:
* Fixed rare `NullReferenceException` in SMAPI's error-handling.
## 3.12.2
Released 05 August 2021 for Stardew Valley 1.5.4 or later.

View File

@ -12,6 +12,8 @@ namespace StardewModdingAPI.Internal
/// <summary>Get a string representation of an exception suitable for writing to the error log.</summary>
/// <param name="exception">The error to summarize.</param>
public static string GetLogSummary(this Exception exception)
{
try
{
switch (exception)
{
@ -25,7 +27,12 @@ namespace StardewModdingAPI.Internal
return summary;
default:
return exception.ToString();
return exception?.ToString() ?? $"<null exception>\n{Environment.StackTrace}";
}
}
catch (Exception ex)
{
throw new InvalidOperationException($"Failed handling {exception?.GetType().FullName} (original message: {exception?.Message})", ex);
}
}