diff options
Diffstat (limited to 'src/StardewModdingAPI')
-rw-r--r-- | src/StardewModdingAPI/Framework/InternalExtensions.cs | 23 | ||||
-rw-r--r-- | src/StardewModdingAPI/Inheritance/SGame.cs | 5 | ||||
-rw-r--r-- | src/StardewModdingAPI/Program.cs | 16 |
3 files changed, 32 insertions, 12 deletions
diff --git a/src/StardewModdingAPI/Framework/InternalExtensions.cs b/src/StardewModdingAPI/Framework/InternalExtensions.cs index d08d12f3..71f70fd5 100644 --- a/src/StardewModdingAPI/Framework/InternalExtensions.cs +++ b/src/StardewModdingAPI/Framework/InternalExtensions.cs @@ -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; + } } } diff --git a/src/StardewModdingAPI/Inheritance/SGame.cs b/src/StardewModdingAPI/Inheritance/SGame.cs index 5484bfc2..93d56553 100644 --- a/src/StardewModdingAPI/Inheritance/SGame.cs +++ b/src/StardewModdingAPI/Inheritance/SGame.cs @@ -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) diff --git a/src/StardewModdingAPI/Program.cs b/src/StardewModdingAPI/Program.cs index 5561aeec..0871e98a 100644 --- a/src/StardewModdingAPI/Program.cs +++ b/src/StardewModdingAPI/Program.cs @@ -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); } } } |