Skip to content

Commit

Permalink
fix(Crash::NoError): Fix crashing without error
Browse files Browse the repository at this point in the history
This should show an error to the user and log the problem properly.

Fixes SOUNDSWITCH-BQ
Fixes SOUNDSWITCH-BS
Fixes SOUNDSWITCH-BR
  • Loading branch information
Belphemur committed Feb 2, 2023
1 parent 1e2f2fd commit 4d2ee17
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions SoundSwitch/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,7 @@ private static void HandleException(Exception exception)
if (exception == null)
return;

SentryId eventId = default;
SentrySdk.WithScope(scope =>
{
scope.AddAttachment(AppConfigs.Configuration.FileLocation);
eventId = SentrySdk.CaptureException(exception);
}
);
var eventId = SentrySdk.CaptureException(exception, scope => { scope.AddAttachment(AppConfigs.Configuration.FileLocation); });

var exceptionMessage = exception.Message;
if (exception.InnerException != null)
Expand All @@ -224,10 +218,25 @@ private static void HandleException(Exception exception)
Would you like to share more information with the developers?";
var result = DialogResult.None;
var syncContext = _synchronizationContext ?? SynchronizationContext.Current;
syncContext.Send(state =>
syncContext?.Send(state =>
{
result = MessageBox.Show(message, $@"{Application.ProductName} crashed...", MessageBoxButtons.YesNo,
MessageBoxIcon.Error);
try
{
try
{
result = MessageBox.Show(message, $@"{Application.ProductName} crashed...", MessageBoxButtons.YesNo,
MessageBoxIcon.Error);
}
catch (InvalidOperationException)
{
result = MessageBox.Show(message, $@"{Application.ProductName} crashed...", MessageBoxButtons.YesNo,
MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
}
}
catch (Exception)
{
Log.Warning("Couldn't warn the user about the crash");
}
}, null);


Expand Down

0 comments on commit 4d2ee17

Please sign in to comment.