Skip to content

Commit

Permalink
Inline variables.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mailaender committed Oct 23, 2022
1 parent 71956cb commit c9fa988
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions OpenRA.Game/Support/ExceptionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,25 @@ public static void HandleFatalError(Exception ex)
Log.AddChannel("exception", exceptionName);

if (Game.EngineVersion != null)
Log.Write("exception", "OpenRA engine version {0}", Game.EngineVersion);
Log.Write("exception", $"OpenRA engine version {Game.EngineVersion}");

if (Game.ModData != null)
{
var mod = Game.ModData.Manifest.Metadata;
Log.Write("exception", "{0} mod version {1}", mod.Title, mod.Version);
Log.Write("exception", $"{mod.Title} mod version ${mod.Version}");
}

if (Game.OrderManager != null && Game.OrderManager.World != null && Game.OrderManager.World.Map != null)
{
var map = Game.OrderManager.World.Map;
Log.Write("exception", "on map {0} ({1} by {2}).", map.Uid, map.Title, map.Author);
Log.Write("exception", $"on map {map.Uid} ({map.Title} by {map.Author}).");
}

Log.Write("exception", "Date: {0:u}", DateTime.UtcNow);
Log.Write("exception", "Operating System: {0} ({1})", Platform.CurrentPlatform, Environment.OSVersion);
Log.Write("exception", "Runtime Version: {0}", Platform.RuntimeVersion);
Log.Write("exception", $"Date: {DateTime.UtcNow:u}");
Log.Write("exception", $"Operating System: {Platform.CurrentPlatform} ({Environment.OSVersion})");
Log.Write("exception", $"Runtime Version: {Platform.RuntimeVersion}", Platform.RuntimeVersion);
var rpt = BuildExceptionReport(ex).ToString();
Log.Write("exception", "{0}", rpt);
Log.Write("exception", rpt);
Console.Error.WriteLine(rpt);
}

Expand All @@ -61,26 +61,26 @@ static StringBuilder BuildExceptionReport(Exception ex, StringBuilder sb, int in
if (ex == null)
return sb;

sb.AppendIndentedFormatLine(indent, "Exception of type `{0}`: {1}", ex.GetType().FullName, ex.Message);
sb.AppendIndentedFormatLine(indent, $"Exception of type `{ex.GetType().FullName}`: {ex.Message}");

if (ex is TypeLoadException tle)
{
sb.AppendIndentedFormatLine(indent, "TypeName=`{0}`", tle.TypeName);
sb.AppendIndentedFormatLine(indent, $"TypeName=`{tle.TypeName}`");
}
else if (ex is OutOfMemoryException)
{
var gcMemoryBeforeCollect = GC.GetTotalMemory(false);
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
sb.AppendIndentedFormatLine(indent, "GC Memory (post-collect)={0:N0}", GC.GetTotalMemory(false));
sb.AppendIndentedFormatLine(indent, "GC Memory (pre-collect)={0:N0}", gcMemoryBeforeCollect);
sb.AppendIndentedFormatLine(indent, $"GC Memory (post-collect)={GC.GetTotalMemory(false):N0}");
sb.AppendIndentedFormatLine(indent, $"GC Memory (pre-collect)={gcMemoryBeforeCollect:N0}");

using (var p = Process.GetCurrentProcess())
{
sb.AppendIndentedFormatLine(indent, "Working Set={0:N0}", p.WorkingSet64);
sb.AppendIndentedFormatLine(indent, "Private Memory={0:N0}", p.PrivateMemorySize64);
sb.AppendIndentedFormatLine(indent, "Virtual Memory={0:N0}", p.VirtualMemorySize64);
sb.AppendIndentedFormatLine(indent, $"Working Set={p.WorkingSet64:N0}");
sb.AppendIndentedFormatLine(indent, $"Private Memory={p.PrivateMemorySize64:N0}");
sb.AppendIndentedFormatLine(indent, $"Virtual Memory={p.VirtualMemorySize64:N0}");
}
}
else
Expand All @@ -94,7 +94,7 @@ static StringBuilder BuildExceptionReport(Exception ex, StringBuilder sb, int in
BuildExceptionReport(ex.InnerException, sb, indent + 1);
}

sb.AppendIndentedFormatLine(indent, "{0}", ex.StackTrace);
sb.AppendIndentedFormatLine(indent, ex.StackTrace);

return sb;
}
Expand Down

0 comments on commit c9fa988

Please sign in to comment.