Skip to content

Commit 4d2ee17

Browse files
committed
fix(Crash::NoError): Fix crashing without error
This should show an error to the user and log the problem properly. Fixes SOUNDSWITCH-BQ Fixes SOUNDSWITCH-BS Fixes SOUNDSWITCH-BR
1 parent 1e2f2fd commit 4d2ee17

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

SoundSwitch/Program.cs

+19-10
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,7 @@ private static void HandleException(Exception exception)
202202
if (exception == null)
203203
return;
204204

205-
SentryId eventId = default;
206-
SentrySdk.WithScope(scope =>
207-
{
208-
scope.AddAttachment(AppConfigs.Configuration.FileLocation);
209-
eventId = SentrySdk.CaptureException(exception);
210-
}
211-
);
205+
var eventId = SentrySdk.CaptureException(exception, scope => { scope.AddAttachment(AppConfigs.Configuration.FileLocation); });
212206

213207
var exceptionMessage = exception.Message;
214208
if (exception.InnerException != null)
@@ -224,10 +218,25 @@ private static void HandleException(Exception exception)
224218
Would you like to share more information with the developers?";
225219
var result = DialogResult.None;
226220
var syncContext = _synchronizationContext ?? SynchronizationContext.Current;
227-
syncContext.Send(state =>
221+
syncContext?.Send(state =>
228222
{
229-
result = MessageBox.Show(message, $@"{Application.ProductName} crashed...", MessageBoxButtons.YesNo,
230-
MessageBoxIcon.Error);
223+
try
224+
{
225+
try
226+
{
227+
result = MessageBox.Show(message, $@"{Application.ProductName} crashed...", MessageBoxButtons.YesNo,
228+
MessageBoxIcon.Error);
229+
}
230+
catch (InvalidOperationException)
231+
{
232+
result = MessageBox.Show(message, $@"{Application.ProductName} crashed...", MessageBoxButtons.YesNo,
233+
MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
234+
}
235+
}
236+
catch (Exception)
237+
{
238+
Log.Warning("Couldn't warn the user about the crash");
239+
}
231240
}, null);
232241

233242

0 commit comments

Comments
 (0)