Skip to content

Commit

Permalink
Move exception handling outside of PrettyConfig
Browse files Browse the repository at this point in the history
Callers really shouldn't be trying to print the result if it resulted in
an exception anyway
  • Loading branch information
blowfishpro committed Sep 23, 2017
1 parent 824b077 commit ac0a149
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions ModuleManager/MMPatchLoader.cs
Expand Up @@ -813,7 +813,15 @@ private void CheckNeeds(IEnumerable<string> 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);
}
}
}
}
Expand Down Expand Up @@ -1050,7 +1058,15 @@ public IEnumerator ApplyPatch(string Stage, IEnumerable<UrlDir.UrlConfig> 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)
{
Expand Down Expand Up @@ -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();
}

Expand Down

0 comments on commit ac0a149

Please sign in to comment.