Skip to content

Commit

Permalink
Improve init failure logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gwindalmir committed Jun 15, 2023
1 parent 0302588 commit de20c98
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
4 changes: 2 additions & 2 deletions MEWorkshopTool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public static int Main(string[] args)
int resultCode = game.InitGame(args);
return resultCode;
}
catch
catch (Exception e)
{
CheckForUpdate();
CheckForUpdate(e);
throw;
}
}
Expand Down
4 changes: 2 additions & 2 deletions SEWorkshopTool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public static int Main(string[] args)
var game = new SpaceGame();
return game.InitGame(args);
}
catch
catch(Exception e)
{
CheckForUpdate();
CheckForUpdate(e);
throw;
}
}
Expand Down
2 changes: 1 addition & 1 deletion WorkshopToolCommon/GameBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public virtual int InitGame(string[] args)
}
catch (Exception ex)
{
ProgramBase.CheckForUpdate();
ProgramBase.CheckForUpdate(ex);
ex.Log("ERROR: An exception occurred initializing game libraries: ");
return Cleanup(2);
}
Expand Down
13 changes: 12 additions & 1 deletion WorkshopToolCommon/ProgramBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ namespace Phoenix.WorkshopTool
// DO NOT REFERENCE GAME LIBRARIES HERE!
public abstract class ProgramBase
{
internal static void CheckForUpdate(Action<string> logMethod = null, Action<string> errorMethod = null)
internal static void CheckForUpdate(Exception exception)
{
CheckForUpdate(null, null, exception);
}

internal static void CheckForUpdate(Action<string> logMethod = null, Action<string> errorMethod = null, Exception exception = null)
{
// Direct log to console, in an attempt to check for an update if there's
// an initialization problem (ie. game updated, and many runtime errors).
Expand All @@ -20,6 +25,12 @@ internal static void CheckForUpdate(Action<string> logMethod = null, Action<stri
if (errorMethod == null)
errorMethod = Console.Error.WriteLine;

if (exception != null)
{
ConsoleWriteColored(ConsoleColor.Red, () => errorMethod(string.Format("Unexpected error occurred: {0}", exception.Message)));
ConsoleWriteColored(ConsoleColor.Yellow, () => errorMethod("Has the game updated?"));
}

try
{
var updateChecker = new UpdateChecker(prereleases: true);
Expand Down

0 comments on commit de20c98

Please sign in to comment.