Skip to content
This repository has been archived by the owner on Nov 14, 2017. It is now read-only.

Commit

Permalink
Include inner exception messages in npk2gif error output.
Browse files Browse the repository at this point in the history
Important troubleshooting information can be in there.
  • Loading branch information
LHCGreg authored and LHCGreg committed Jul 20, 2015
1 parent 79b2904 commit f16a67a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
19 changes: 19 additions & 0 deletions DFO.Utilities/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,24 @@ public static ushort LeToNativeUInt16(byte[] buffer, int offset)
return ret;
}
}

/// <summary>
/// Returns ex.Message: innerex1.Message: innerex2.Message, etc
/// </summary>
/// <param name="ex"></param>
/// <returns></returns>
public static string GetExceptionMessageWithInnerExceptions(Exception ex)
{
StringBuilder message = new StringBuilder(ex.Message);

Exception innerEx = ex.InnerException;
while (innerEx != null)
{
message.Append(": ").Append(innerEx.Message);
innerEx = innerEx.InnerException;
}

return message.ToString();
}
}
}
11 changes: 6 additions & 5 deletions npk2gif/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using DFO.Common.Images;
using DFO.Images;
using DFO.Npk;
using DFO.Utilities;
using NDesk.Options;

namespace DFO.npk2gif
Expand Down Expand Up @@ -41,7 +42,7 @@ static void Main(string[] args)
}
catch (Exception ex)
{
Console.Error.WriteLine("Error creating GIF: {0}", ex.Message);
Console.Error.WriteLine("Error creating GIF: {0}", Utils.GetExceptionMessageWithInnerExceptions(ex));
Console.Error.WriteLine(ex.StackTrace);
giffer.Dispose();
gifOutputStream.Dispose();
Expand All @@ -60,7 +61,7 @@ static void Main(string[] args)
}
catch (Exception ex)
{
Console.Error.WriteLine("Unexpected error: {0}", ex.Message);
Console.Error.WriteLine("Unexpected error: {0}", Utils.GetExceptionMessageWithInnerExceptions(ex));
Console.Error.WriteLine(ex.StackTrace);
}
}
Expand All @@ -84,7 +85,7 @@ private static NpkReader LoadNpk(string path)
}
catch (NpkException ex)
{
Console.Error.WriteLine("There was an error while loading the NPK file. The file format may have changed. Here is some information that may help debug the issue: {0}\n\n{1}", ex.Message, ex.StackTrace);
Console.Error.WriteLine("There was an error while loading the NPK file. The file format may have changed. Here is some information that may help debug the issue: {0}\n\n{1}", Utils.GetExceptionMessageWithInnerExceptions(ex), ex.StackTrace);
Environment.Exit(1);
}
catch (Exception ex)
Expand Down Expand Up @@ -190,7 +191,7 @@ private static void CreateOutputDir(string outputPath)
}
catch (Exception ex)
{
Console.Error.WriteLine("Error creating output directory for {0}: {1}", outputPath, ex.Message);
Console.Error.WriteLine("Error creating output directory for {0}: {1}", outputPath, Utils.GetExceptionMessageWithInnerExceptions(ex));
Environment.Exit(1);
}
}
Expand All @@ -203,7 +204,7 @@ private static FileStream OpenOutput(string outputPath)
}
catch (Exception ex)
{
Console.Error.WriteLine("Error opening {0} for output: {1}", outputPath, ex.Message);
Console.Error.WriteLine("Error opening {0} for output: {1}", outputPath, Utils.GetExceptionMessageWithInnerExceptions(ex));
Environment.Exit(1);
return null; // not reached
}
Expand Down

0 comments on commit f16a67a

Please sign in to comment.