log relevant details when a ReflectionTypeLoadException is caught by SMAPI
This commit is contained in:
parent
651388c818
commit
1dc3f1013f
|
@ -8,6 +8,9 @@ For players:
|
|||
* Fixed errors in some mod event handlers crashing the game.
|
||||
* Fixed issue where an error in one mod's event handler would cause other mods' handlers to never be called.
|
||||
|
||||
For developers:
|
||||
* Improved logging to show relevant details when a `ReflectionTypeLoadException` is caught by SMAPI.
|
||||
|
||||
## 1.1
|
||||
See [log](https://github.com/CLxS/SMAPI/compare/1.0...1.1.1).
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace StardewModdingAPI.Framework
|
||||
{
|
||||
|
@ -32,7 +33,7 @@ namespace StardewModdingAPI.Framework
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
monitor.Log($"A mod failed handling the {name} event:\n{ex}", LogLevel.Error);
|
||||
monitor.Log($"A mod failed handling the {name} event:\n{ex.GetLogSummary()}", LogLevel.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -57,9 +58,27 @@ namespace StardewModdingAPI.Framework
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
monitor.Log($"A mod failed handling the {name} event:\n{ex}", LogLevel.Error);
|
||||
monitor.Log($"A mod failed handling the {name} event:\n{ex.GetLogSummary()}", LogLevel.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/****
|
||||
** Exceptions
|
||||
****/
|
||||
/// <summary>Get a string representation of an exception suitable for writing to the error log.</summary>
|
||||
/// <param name="exception">The error to summarise.</param>
|
||||
public static string GetLogSummary(this Exception exception)
|
||||
{
|
||||
string summary = exception.ToString();
|
||||
|
||||
if (exception is ReflectionTypeLoadException)
|
||||
{
|
||||
foreach (Exception childEx in ((ReflectionTypeLoadException)exception).LoaderExceptions)
|
||||
summary += $"\n\n{childEx.GetLogSummary()}";
|
||||
}
|
||||
|
||||
return summary;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ using Microsoft.Xna.Framework;
|
|||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using StardewModdingAPI.Events;
|
||||
using StardewModdingAPI.Framework;
|
||||
using StardewValley;
|
||||
using StardewValley.BellsAndWhistles;
|
||||
using StardewValley.Locations;
|
||||
|
@ -334,7 +335,7 @@ namespace StardewModdingAPI.Inheritance
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.Monitor.Log($"An error occured in the base update loop: {ex}", LogLevel.Error);
|
||||
this.Monitor.Log($"An error occured in the base update loop: {ex.GetLogSummary()}", LogLevel.Error);
|
||||
Console.ReadKey();
|
||||
}
|
||||
|
||||
|
@ -766,7 +767,7 @@ namespace StardewModdingAPI.Inheritance
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.Monitor.Log($"An error occured in the overridden draw loop: {ex}", LogLevel.Error);
|
||||
this.Monitor.Log($"An error occured in the overridden draw loop: {ex.GetLogSummary()}", LogLevel.Error);
|
||||
}
|
||||
|
||||
if (SGame.Debug)
|
||||
|
|
|
@ -142,7 +142,7 @@ namespace StardewModdingAPI
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Program.Monitor.Log($"Critical error: {ex}", LogLevel.Error);
|
||||
Program.Monitor.Log($"Critical error: {ex.GetLogSummary()}", LogLevel.Error);
|
||||
}
|
||||
Program.PressAnyKeyToExit();
|
||||
}
|
||||
|
@ -179,7 +179,7 @@ namespace StardewModdingAPI
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Program.Monitor.Log($"Couldn't check for a new version of SMAPI. This won't affect your game, but you may not be notified of new versions if this keeps happening.\n{ex}");
|
||||
Program.Monitor.Log($"Couldn't check for a new version of SMAPI. This won't affect your game, but you may not be notified of new versions if this keeps happening.\n{ex.GetLogSummary()}");
|
||||
}
|
||||
}).Start();
|
||||
}
|
||||
|
@ -198,7 +198,7 @@ namespace StardewModdingAPI
|
|||
|
||||
// add error interceptors
|
||||
#if SMAPI_FOR_WINDOWS
|
||||
Application.ThreadException += (sender, e) => Program.Monitor.Log($"Critical thread exception: {e.Exception}", LogLevel.Error);
|
||||
Application.ThreadException += (sender, e) => Program.Monitor.Log($"Critical thread exception: {e.Exception.GetLogSummary()}", LogLevel.Error);
|
||||
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
|
||||
#endif
|
||||
AppDomain.CurrentDomain.UnhandledException += (sender, e) => Program.Monitor.Log($"Critical app domain exception: {e.ExceptionObject}", LogLevel.Error);
|
||||
|
@ -262,7 +262,7 @@ namespace StardewModdingAPI
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Program.Monitor.Log($"SMAPI encountered a fatal error:\n{ex}", LogLevel.Error);
|
||||
Program.Monitor.Log($"SMAPI encountered a fatal error:\n{ex.GetLogSummary()}", LogLevel.Error);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -277,7 +277,7 @@ namespace StardewModdingAPI
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Program.Monitor.Log($"Couldn't create a path: {path}\n\n{ex}", LogLevel.Error);
|
||||
Program.Monitor.Log($"Couldn't create a path: {path}\n\n{ex.GetLogSummary()}", LogLevel.Error);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -330,7 +330,7 @@ namespace StardewModdingAPI
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Program.Monitor.Log($"{errorPrefix}: manifest parsing failed.\n{ex}", LogLevel.Error);
|
||||
Program.Monitor.Log($"{errorPrefix}: manifest parsing failed.\n{ex.GetLogSummary()}", LogLevel.Error);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -369,7 +369,7 @@ namespace StardewModdingAPI
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Program.Monitor.Log($"{errorPrefix}: couldm't create the per-save configuration directory ('psconfigs') requested by this mod.\n{ex}", LogLevel.Error);
|
||||
Program.Monitor.Log($"{errorPrefix}: couldm't create the per-save configuration directory ('psconfigs') requested by this mod.\n{ex.GetLogSummary()}", LogLevel.Error);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -417,7 +417,7 @@ namespace StardewModdingAPI
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Program.Monitor.Log($"{errorPrefix}: an error occurred while loading the target DLL.\n{ex}", LogLevel.Error);
|
||||
Program.Monitor.Log($"{errorPrefix}: an error occurred while loading the target DLL.\n{ex.GetLogSummary()}", LogLevel.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue