Skip to content

Commit

Permalink
Misc: Partially revert last commit 644b0f
Browse files Browse the repository at this point in the history
Lets not shallow all exceptions... (this ended badly in my short testing)
  • Loading branch information
Piotrekol committed Apr 25, 2019
1 parent ce23e16 commit c3d4471
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 30 deletions.
7 changes: 3 additions & 4 deletions osu!StreamCompanion/Code/Windows/ErrorFrm.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 28 additions & 26 deletions osu!StreamCompanion/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace osu_StreamCompanion
{
static class Program
{
public static string ScVersion ="v190424.19";
public static string ScVersion ="v190425.19";
private static Initializer _initializer;
private const bool AllowMultiInstance = false;

Expand Down Expand Up @@ -124,7 +124,7 @@ static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEv
}
else
{
#if DEBUG
#if !DEBUG
throw (Exception)e.ExceptionObject;
#endif
Exception ex = null;
Expand All @@ -138,36 +138,40 @@ static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEv
HandleException(ex);
}
}

private static (bool ForceQuit, bool SendReport, string Message) GetErrorData()
private static (bool SendReport, string Message) GetErrorData()
{
if (Exceptions.Count <= 4)
return (false, true, $"{errorNotificationFormat} {willAttemptToRun} {messageWasSent}");
// ReSharper disable ConditionIsAlwaysTrueOrFalse
bool sendReport = false;

#if WITHSENTRY
sendReport = true;
#endif

if (sendReport)
return (true, $"{errorNotificationFormat} {needToExit} {messageWasSent}");

return (false, false, $"{errorNotificationFormat} {willAttemptToRun} {messageWasNotSent}");
return (false, $"{errorNotificationFormat} {needToExit} {privateBuildMessageNotSent}");

// ReSharper restore ConditionIsAlwaysTrueOrFalse
}

private static string errorNotificationFormat = @"There was unhandled problem with a program";
private static string needToExit = @"and it needs to exit.";
private static string willAttemptToRun = @"but it will attempt to run.";

private static string messageWasSent = "Error report was sent to Piotrekol.";
private static string messageWasNotSent = "Any further errors will !not! be sent to Piotrekol until StreamCompanion restarts.";

private static List<Exception> Exceptions { get; set; }
private static string privateBuildMessageNotSent = "This is private build, so error report WAS NOT SENT.";

public static void HandleException(Exception ex)
{
bool shouldQuit = true;
try
{
ex.Data["ExceptionCount"] = Exceptions.Count;
Exceptions.Add(ex);

ex.Data.Add("netFramework", GetDotNetVersion.Get45PlusFromRegistry());

var errorConsensus = GetErrorData();
shouldQuit = errorConsensus.ForceQuit;

#if DEBUG
#if WITHSENTRY
if (errorConsensus.SendReport)
{
var ravenClient = SentryLogger.RavenClient;
Expand All @@ -176,22 +180,20 @@ public static void HandleException(Exception ex)
ravenClient.Capture(sentryEvent);
}
#endif

MessageBox.Show(errorConsensus.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
var form = new Error(ex.Message + Environment.NewLine + ex.StackTrace, !errorConsensus.ForceQuit ? "StreamCompanion will attempt to run" : null);
var form = new Error(ex.Message + Environment.NewLine + ex.StackTrace, null);
form.ShowDialog();
}
finally
{
if (shouldQuit)
try
{
try
{
SafeQuit();
}
catch
{
_initializer.ExitThread();
}
SafeQuit();
}
catch
{
_initializer.ExitThread();
}
}
}
Expand Down

0 comments on commit c3d4471

Please sign in to comment.