From ac0a149a21efe830c2c8e7df2468526395b6fe6d Mon Sep 17 00:00:00 2001 From: blowfish Date: Sat, 23 Sep 2017 12:00:50 -0700 Subject: [PATCH] Move exception handling outside of PrettyConfig Callers really shouldn't be trying to print the result if it resulted in an exception anyway --- ModuleManager/MMPatchLoader.cs | 39 +++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/ModuleManager/MMPatchLoader.cs b/ModuleManager/MMPatchLoader.cs index 3008284f..74edc282 100644 --- a/ModuleManager/MMPatchLoader.cs +++ b/ModuleManager/MMPatchLoader.cs @@ -813,7 +813,15 @@ private void CheckNeeds(IEnumerable mods, IPatchProgress progress) catch (Exception ex) { progress.Exception(currentMod, "Exception while checking needs : " + currentMod.SafeUrl() + " with a type of " + currentMod.type, ex); - logger.Error("Node is : " + PrettyConfig(currentMod)); + + try + { + logger.Error("Node is : " + PrettyConfig(currentMod)); + } + catch(Exception ex2) + { + logger.Exception("Exception while attempting to print a node", ex2); + } } } } @@ -1050,7 +1058,15 @@ public IEnumerator ApplyPatch(string Stage, IEnumerable patche catch (Exception e) { progress.Exception(mod, "Exception while processing node : " + mod.SafeUrl(), e); - logger.Error("Processed node was\n" + PrettyConfig(mod)); + + try + { + logger.Error("Processed node was\n" + PrettyConfig(mod)); + } + catch (Exception ex2) + { + logger.Exception("Exception while attempting to print a node", ex2); + } } if (nextYield < Time.realtimeSinceStartup) { @@ -2229,26 +2245,19 @@ private static void InsertValue(ConfigNode newNode, int index, string name, stri newNode.AddValue(name, value); } - private string PrettyConfig(UrlDir.UrlConfig config) + private static string PrettyConfig(UrlDir.UrlConfig config) { StringBuilder sb = new StringBuilder(); sb.AppendFormat("{0}[{1}]\n", config.type ?? "NULL", config.name ?? "NULL"); - try + if (config.config != null) { - if (config.config != null) - { - config.config.PrettyPrint(ref sb, " "); - } - else - { - sb.Append("NULL\n"); - } - sb.Append("\n"); + config.config.PrettyPrint(ref sb, " "); } - catch (Exception e) + else { - logger.Exception("PrettyConfig Exception", e); + sb.Append("NULL\n"); } + sb.Append("\n"); return sb.ToString(); }